友盟推送android 8.0系统不显示推送消息问题_第1张图片

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();                }
这样就完美解决能收到推送消息,但是通知栏不显示的问题

更多相关文章

  1. 基于MQTT实现Android消息推送(Push)
  2. 浅析Android中的消息机制-解决:Only the original thread that cr
  3. Android异步消息机制之Handler
  4. Android开发之消息处理机制(一)——Handler
  5. Titanium 使用刘明星的Jpush module做android端的消息推送
  6. android中json文件的写法
  7. Android UI控件详解-Button(按钮)点击事件的5种写法
  8. Android notification点击跳转到Activity,点击返回跳转,前一条消息

随机推荐

  1. Android-使用AutoCompleteTextView进行动
  2. Android Studio自带模拟器读写SDcard不成
  3. android 获取sim卡运营商信息
  4. Android(安卓)EditText(一)——EditText
  5. Android的SMS短消息格式和主要字段
  6. 动画学习笔记-Android Animation
  7. 【设计模式与Android】建造者模式——建
  8. Android(安卓)Compile
  9. Android权限问题整理
  10. Android 手动显示和隐藏软键盘 android