Android 9.0版本及以上开发时遇到的一些版本问题

Android 9.0版本及以上开发时遇到的一些版本问题,第1张

概述1.使用前台服务要加上权限<uses-permissionandroid:name="android.permission.FOREGROUND_SERVICE"/>同时通知部分的代码也要修改//android8.0以后新增StringCHANNEL_ONE_ID="com.example.servicetest";StringCHANNEL_ONE_NAME="ChannelO

1.使用前台服务

要加上权限

<uses-permission androID:name="androID.permission.FOREGROUND_SERVICE" />

同时通知部分的代码也要修改

//androID 8.0以后新增        String CHANNEL_ONE_ID="com.example.servicetest";        String CHANNEL_ONE_name = "Channel One";        NotificationChannel notificationChannel = null;        if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.O){            notificationChannel = new NotificationChannel(CHANNEL_ONE_ID,CHANNEL_ONE_name, notificationmanager.importANCE_HIGH);            notificationChannel.enablelights(true);            notificationChannel.setlightcolor(color.RED);            notificationChannel.setShowBadge(true);            notificationChannel.setLockscreenVisibility(Notification.VISIBIliTY_PUBliC);            notificationmanager manager = (notificationmanager)getSystemService(NOTIFICATION_SERVICE);            manager.createNotificationChannel(notificationChannel);            //创建前台服务            Intent intent = new Intent(this,MainActivity.class);            PendingIntent pi = PendingIntent.getActivity(this,0,intent,0);            Notification notification = new Notification.Builder(this)                    .setChannelID(CHANNEL_ONE_ID)//新增                    .setContentTitle("This is content Title")                    .setContentText("This is content Title")                    .setWhen(System.currentTimeMillis())                    .setSmallicon(R.mipmap.ic_launcher)                    .setContentIntent(pi)                    .build();            notification.flags |= Notification.FLAG_NO_CLEAR;//新增            startForeground(1,notification);        }

 

总结

以上是内存溢出为你收集整理的Android 9.0版本及以上开发时遇到的一些版本问题全部内容,希望文章能够帮你解决Android 9.0版本及以上开发时遇到的一些版本问题所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址:https://www.54852.com/web/1066736.html

(0)
打赏 微信扫一扫微信扫一扫 支付宝扫一扫支付宝扫一扫
上一篇 2022-05-26
下一篇2022-05-26

发表评论

登录后才能评论

评论列表(0条)

    保存