Android O中修改NotificationChannel 属性,升级app后该修改不生效,必须卸载app重新安装才能生效

简介: Android O中修改NotificationChannel 属性,升级app后该修改不生效,必须卸载app重新安装才能生效

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

1.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不同。


目录
相关文章
|
9月前
|
监控 Shell Linux
Android调试终极指南:ADB安装+多设备连接+ANR日志抓取全流程解析,覆盖环境变量配置/多设备调试/ANR日志分析全流程,附Win/Mac/Linux三平台解决方案
ADB(Android Debug Bridge)是安卓开发中的重要工具,用于连接电脑与安卓设备,实现文件传输、应用管理、日志抓取等功能。本文介绍了 ADB 的基本概念、安装配置及常用命令。包括:1) 基本命令如 `adb version` 和 `adb devices`;2) 权限操作如 `adb root` 和 `adb shell`;3) APK 操作如安装、卸载应用;4) 文件传输如 `adb push` 和 `adb pull`;5) 日志记录如 `adb logcat`;6) 系统信息获取如屏幕截图和录屏。通过这些功能,用户可高效调试和管理安卓设备。
|
Android开发
解决android apk安装后出现2个相同的应用图标
解决android apk安装后出现2个相同的应用图标
871 2
|
开发工具 Android开发 Windows
Android Studio安装Unable to access Android SDK add-on list处理方法
Android Studio安装Unable to access Android SDK add-on list处理方法
3074 1
|
XML API Android开发
android S 上 安装apk出现android.os.FileUriExposedException
android S 上 安装apk出现android.os.FileUriExposedException
441 6
|
Shell 开发工具 Android开发
|
Oracle Java 关系型数据库
Android studio 安装以及第一个程序
Android studio 安装以及第一个程序
405 0
|
存储 Android开发
详细解读Android获取已安装应用信息(图标,名称,版本号,包)
详细解读Android获取已安装应用信息(图标,名称,版本号,包)
616 0
|
Android开发 Kotlin
kotlin开发安卓应用 如何修改app安装后的名称
在 Android 应用中,要修改安装后的显示名称,需更新 AndroidManifest.xml 文件中 application 标签的 android:label 属性。可直接在该属性内设置新名称,或在 res/values/strings.xml 文件中修改 app_name 并在 manifest 中引用。推荐使用 strings.xml 方式,以便支持多语言和集中管理。
|
传感器 编解码 物联网
03. 【Android教程】Genymotion 的安装与使用
03. 【Android教程】Genymotion 的安装与使用
889 0
|
XML Dart Java
Flutter插件开发之APK自动安装,字节跳动Android岗面试题
Flutter插件开发之APK自动安装,字节跳动Android岗面试题

热门文章

最新文章