Android Notification一些坑

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/zh_qianwei/article/details/89176836

Android0上运行以前正常的notice可能会有各种问题

  • 1.通知栏不显示

第一步添加代码如下

 NotificationManager notificationManager = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
            String channel = AppUtil.getChannel();
            NotificationChannel mChannel = new NotificationChannel(context.getPackageName(), channel, NotificationManager.IMPORTANCE_LOW);
            notificationManager.createNotificationChannel(mChannel);
        }

第二:部分机型(比如vivio)需要在设置里面打开对应应用的通知开关

  • 2.通知栏点击没反应
    需要添加代码如下:
 Intent broadcastIntent = new Intent(actionNAme);
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
            broadcastIntent.setClass(context, A.Class);
        }

官方说明
I ran into the same, in Android Oreo you need to make it a explicit Intent (is not enough with putting the receiver on the manifest, in fact, it won’t pay attention to that), so when you make the intent, make it explicit using the setClass method:

猜你喜欢

转载自blog.csdn.net/zh_qianwei/article/details/89176836
今日推荐