友盟推送android 8.0系统不显示推送消息问题
16lz
2021-01-23
android各版本对应的api情况,而android8.0以及之后的版本,notifycation为了更安全,又增加了channel的写法,代码如下
if (Build.VERSION.SDK_INT >= 26) { NotificationManager manager = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE); NotificationChannel channel = new NotificationChannel("channel_id", "channel_name", NotificationManager.IMPORTANCE_HIGH); if (manager != null) { manager.createNotificationChannel(channel); } Notification.Builder builder = new Notification.Builder(context, "channel_id"); builder.setSmallIcon(R.mipmap.ic_launcher) .setWhen(System.currentTimeMillis()) .setLargeIcon(BitmapFactory.decodeResource(context.getResources(), R.mipmap.ic_launcher)) .setContentTitle(msg.title) .setContentText(msg.text) .setAutoCancel(true); return builder.build(); } else { Notification.Builder builder = new Notification.Builder(context); builder.setSmallIcon(R.mipmap.ic_launcher) .setWhen(System.currentTimeMillis()) .setLargeIcon(BitmapFactory.decodeResource(context.getResources(), R.mipmap.ic_launcher)) .setContentTitle(msg.title) .setContentText(msg.text) .setAutoCancel(true); return builder.build(); }
这样就完美解决能收到推送消息,但是通知栏不显示的问题
更多相关文章
- 基于MQTT实现Android消息推送(Push)
- 浅析Android中的消息机制-解决:Only the original thread that cr
- Android异步消息机制之Handler
- Android开发之消息处理机制(一)——Handler
- Titanium 使用刘明星的Jpush module做android端的消息推送
- android中json文件的写法
- Android UI控件详解-Button(按钮)点击事件的5种写法
- Android notification点击跳转到Activity,点击返回跳转,前一条消息