Notification之适配总结

Posted awkflf11

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Notification之适配总结相关的知识,希望对你有一定的参考价值。


11. android通知栏8.0系统报错误:

 

NotificationService: No Channel found for pkg=xxx.xxx.xxx, channelId=12345, id=12345, tag=null, opPkg=xxx.xxx.xxx, callingUid=10085, userId=0, incomingUserId=0, notificationUid=10085, notification=Notification…
/**
* Notification:8.0系统和8.0系统之下的逻辑
*/
@RequiresApi(api = Build.VERSION_CODES.JELLY_BEAN)
public void postNotification(Context context) {
int channelId = 0x22222;
Notification.Builder builder;
NotificationManager manager = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
//NotificationManagerCompat managerCompat= (NotificationManagerCompat) context.getSystemService(Context.NOTIFICATION_SERVICE);
if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.O) {//8.0系统之上
NotificationChannel channel = new NotificationChannel(String.valueOf(channelId), "chanel_name", NotificationManager.IMPORTANCE_HIGH);
manager.createNotificationChannel(channel);
builder = new Notification.Builder(context, String.valueOf(channelId));
//或者
//builder = new Notification.Builder(context);
//builder.setChannelId(String.valueOf(channelId)); //创建通知时指定channelId
} else {
builder = new Notification.Builder(context);
}
//需要跳转指定的页面
Intent intent = new Intent(context, MainActivity.class);
PendingIntent pendingIntent = PendingIntent.getActivity(context, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT);
builder.setContentIntent(pendingIntent);

builder.setTicker("new message")
.setSmallIcon(R.drawable.ic_launcher_background)
.setContentTitle("标题")
.setContentText("内容")
.setContentIntent(pendingIntent);
manager.notify(channelId, builder.build());
}
pasting

 

































以上是关于Notification之适配总结的主要内容,如果未能解决你的问题,请参考以下文章

Android 自定义Notification颜色适配问题

Android通知栏介绍与适配总结

通知栏Notification在不同手机上显示的问题总结

前端开发知识之前端移动端适配总结

如何将数据从回收器适配器发送到片段 |如何从 recyclerview 适配器调用片段函数

如何从片段适配器启动活动