????????????????????????????????????????????????????????????????? 關(guān)于Android8.0以上系統(tǒng)通知欄不顯示的問題
Android 8.0之前,Google爸爸在通知欄增加了NotificationChannel這個(gè)屬性线定,其實(shí)就是在通知欄builder的時(shí)候需要設(shè)置一個(gè)這樣類型的屬性娜谊,這是Android8.0的新特性,不加的話斤讥,通知欄就沒法顯示纱皆,所以為了適配Android8.0,就需要去判斷了版本號了啊!!!
private int PUSH_NOTIFICATION_ID = (0x001);private String PUSH_CHANNEL_ID = "PUSH_NOTIFY_ID";private ?String PUSH_CHANNEL_NAME = "PUSH_NOTIFY_NAME";
mNotifyManager=(NotificationManager)context.getSystemService(Context.NOTIFICATION_SERVICE);if (Build.VERSION.SDK_INT > Build.VERSION_CODES.O) {
//當(dāng)手機(jī)系統(tǒng)版本號大于8.0的時(shí)候就需要設(shè)置一個(gè)NotificationChannel屬性????mBuilder = new NotificationCompat.Builder(context,PUSH_CHANNEL_ID);????NotificationChannel mChannel = new NotificationChannel(PUSH_CHANNEL_ID, PUSH_CHANNEL_NAME, NotificationManager.IMPORTANCE_HIGH);
????mNotifyManager.createNotificationChannel(mChannel);
????mBuilder.setContentTitle("自己設(shè)置")????????????.setContentText("自己設(shè)置")????????????.setSmallIcon(R.mipmap.ic_launcher_origin)????????????.setChannelId(PUSH_CHANNEL_ID)} else {????mBuilder = new NotificationCompat.Builder(context);????mBuilder.setContentTitle("自己設(shè)置")????????????.setContentText("自己設(shè)置")????????????.setSmallIcon(R.mipmap.ic_launcher_origin);}notification = mBuilder.build();
在我們notify的時(shí)候芭商,即更新通知欄的時(shí)候派草,同樣也不能忘了這個(gè)PUSH_NOTIFICATION_ID
即:mNotifyManager.notify(PUSH_NOTIFICATION_ID, notification);
之后你就可以看到大功告成了呦