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屏幕分辨率正确获取及PX,DPI,DP,SP等的对应关系
  3. IM-A820L限制GSM,WCDMA上网的原理(其他泛泰机型可参考)7.13
  4. Android——开发环境
  5. [置顶] Android(安卓)跨进程通信Aidl的使用及注意事项
  6. Titanium 使用刘明星的Jpush module做android端的消息推送
  7. android中json文件的写法
  8. Android开机启动分析(一)logo的显示
  9. android版本与linux内核版本对应关系

随机推荐

  1. Android开发小技巧
  2. 这些年正Android(安卓)- 大纲
  3. Android控件属性大全[整理]
  4. Android中使用WebView, WebChromeClient
  5. Android[项目] Android天气预报
  6. Android手势ImageView三部曲 第三部
  7. Android之Adapter用法总结
  8. Android(安卓)网络请求库Retrofit简单使
  9. Android学习资源-retrofit,eventBus,butter
  10. 关于调试的一个问题