解决Fail to post notification on channel "null"的方法
程序员文章站
2022-04-18 18:11:09
mNotifyMgr = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);mNotifyMgr.cancelAll(); String title = getString(R.string.filtershow_notific... ......
mnotifymgr = (notificationmanager) getsystemservice(notification_service);
mnotifymgr.cancelall();
string title = getstring(r.string.filtershow_notification_label); if(build.version.sdk_int >= build.version_codes.o) { string id = "channel_1"; notificationchannel channel = new notificationchannel(id, title, notificationmanager.importance_high); mnotifymgr.createnotificationchannel(channel); mbuilder = new notification.builder(this, id) .setcategory(notification.category_event) .setsmallicon(r.drawable.filtershow_button_fx) .setcontenttitle(title) .setcontenttext(getstring(r.string.filtershow_notification_message)) .setautocancel(true); } else { mbuilder = new notification.builder(this) .setsmallicon(r.drawable.filtershow_button_fx) .setcontenttitle(title) .setcontenttext(getstring(r.string.filtershow_notification_message)); }
mnotifymgr.notify(mnotificationid, mbuilder.build());
mnotificationid为1的话,systemui下拉栏会存在对应的通知item(可以用来点击跳转),
如果是0的话,则不会出现.