Android 8.0中修改NotificationChannel 属性,升级app后该修改不生效,必须卸载app重新安装才能生效,原代码如下:

public void notifyDownloading(long progress, long num, String file_name) {    Notification.Builder mBuilder;    mBuilder = new Notification.Builder(MainActivity.this, TAG );    NotificationChannel channel;    channel = new NotificationChannel(TAG , file_name, NotificationManager.IMPORTANCE_LOW);    mNotifyManager.createNotificationChannel(channel);    mBuilder.setSmallIcon(R.drawable.notification_download_icon);    mBuilder.setProgress((int) num, (int) progress, false);    mBuilder.setContentInfo(getPercent((int) progress, (int) num));    mBuilder.setOngoing(true);    mBuilder.setWhen(System.currentTimeMillis());    mBuilder.setContentTitle(file_name);    mBuilder.setContentText("download");    PendingIntent pendIntent = PendingIntent.getActivity(            MainActivity.this, NOTIFY_ID, getCurActivityIntent(), PendingIntent.FLAG_UPDATE_CURRENT);    mBuilder.setContentIntent(pendIntent);    mNotifyManager.notify(NOTIFY_ID, mBuilder.build());}

这里将IMPORTANCE_HIGH修改为IMPORTANCE_LOW,通过Android Studio直接安装,发现修改不生效,app的效果还是IMPORTANCE_HIGH属性的效果。总之,一脸懵逼。。。

经过若干猜测和尝试,发现修改每次创建Notification.Builder的id和NotificationChannel的id就可以规避该问题,修改后代码如下:

public void notifyDownloading(long progress, long num, String file_name) {    Notification.Builder mBuilder;    mBuilder = new Notification.Builder(MainActivity.this, TAG + System.currentTimeMillis());    NotificationChannel channel;    channel = new NotificationChannel(TAG + System.currentTimeMillis(), file_name, NotificationManager.IMPORTANCE_LOW);    mNotifyManager.createNotificationChannel(channel);    mBuilder.setSmallIcon(R.drawable.notification_download_icon);    mBuilder.setProgress((int) num, (int) progress, false);    mBuilder.setContentInfo(getPercent((int) progress, (int) num));    mBuilder.setOngoing(true);    mBuilder.setWhen(System.currentTimeMillis());    mBuilder.setContentTitle(file_name);    mBuilder.setContentText("download");    PendingIntent pendIntent = PendingIntent.getActivity(            MainActivity.this, NOTIFY_ID, getCurActivityIntent(), PendingIntent.FLAG_UPDATE_CURRENT);    mBuilder.setContentIntent(pendIntent);    mNotifyManager.notify(NOTIFY_ID, mBuilder.build());}
通过System.currentTimeMillis()保证每次创建对象的Id不同。

更多相关文章

  1. 【Android】AppCompat V21:将 Materia Design 兼容到5.0之前的设
  2. Android(安卓)Studio同一工程生成不同的app名,包名,图标分别设置
  3. android:priority
  4. android 5 设置图案锁,锁屏界面进入相机拍照、查看锁定的照片后,退
  5. Android重写View并且自定义属性(二)
  6. 微信视频全屏问题解决方案
  7. Android系统的开机画面显示过程分析(8)
  8. Android调用第三方百度APP进行导航
  9. Android-EditText属性大全

随机推荐

  1. android studio for android learning (九
  2. Android之SlidingDrawer抽屉效果
  3. Android(安卓)TV Audio基本框架及启动流
  4. Android异步加载图像小结
  5. [android]android自动化测试八之让你的AV
  6. Android异步处理系列文章
  7. Android(安卓)开发中 Parcel存储类型和数
  8. Android图形选择 - Selector
  9. android的binder机制
  10. 【Android】Android(安卓)监听apk安装替