当前位置: 首页 > article >正文

【Android源码】屏蔽系统通知出现在系统栏中

环境

aosp: android-14.0.0_r1
真机:Pixel5

目标

我想把usb连接的两个系统通知屏蔽掉

  1. “正在通过 USB 为此设备充电”
  2. “已连接到 USB 调试”

步骤

  1. 首先找到这两句内容出现的位置在
    frameworks/base/core/res/res/values-zh-rCN/strings.xml
<string name="usb_charging_notification_title" msgid="1674124518282666955">"正在通过 USB 为此设备充电"</string>

<string name="adb_active_notification_title" msgid="408390247354560331">"已连接到 USB 调试"</string>
<string name="adb_active_notification_message" msgid="5617264033476778211">"点按即可关闭 USB 调试"</string>
  1. 然后找到代码实现的位置
    分别是:
    frameworks/base/core/java/android/debug/AdbNotifications.java
    frameworks/base/services/usb/java/com/android/server/usb/UsbDeviceManager.java
Notification.Builder builder = new Notification.Builder(mContext, channel)
                           .setSmallIcon(com.android.internal.R.drawable.stat_sys_adb)
                           .setWhen(0)
                           .setOngoing(true)
                           .setTicker(title)
                           .setDefaults(0)  // please be quiet
                           .setColor(mContext.getColor(
                                   com.android.internal.R.color
                                           .system_notification_accent_color))
                           .setContentTitle(title)
                           .setContentText(message)
                           .setContentIntent(pi)
                           .setVisibility(Notification.VISIBILITY_PUBLIC);

                   if (titleRes
                           == com.android.internal.R.string
                           .usb_unsupported_audio_accessory_title) {
                       builder.setStyle(new Notification.BigTextStyle()
                               .bigText(message));
                   }
                   Notification notification = builder.build();

                   mNotificationManager.notifyAsUser(null, id, notification,
                           UserHandle.ALL);
                   Slog.d(TAG, "push notification:" + title);
                   Log.w(TAG, "push notification:title=" + title + ";message=" + message);
                   mUsbNotificationId = id;


if (!mAdbNotificationShown) {
  Notification notification = AdbNotifications.createNotification(mContext,
                           AdbTransportType.USB);
  mAdbNotificationShown = true;
  Log.w(TAG, "updateAdbNotification:id=" + id);
  mNotificationManager.notifyAsUser(null, id, notification, UserHandle.ALL);
}

主要是mNotificationManager.notifyAsUser()这个方法,它会把内容都通知出去。所以处理它就行,如果不想要所有的系统通知,屏蔽掉它就行。但我只是不想要两个内容。
修改如下:


Notification notification = builder.build();
if(message != null && !message.equals(r.getText(com.android.internal.R.string.usb_notification_message))) {
	mNotificationManager.notifyAsUser(null, id, notification,UserHandle.ALL);
}


if (!mAdbNotificationShown) {
  Notification notification = AdbNotifications.createNotification(mContext, AdbTransportType.USB);
  mAdbNotificationShown = true;
  //mNotificationManager.notifyAsUser(null, id, notification, UserHandle.ALL);
}

很简单吧,最后测试通过!


http://www.kler.cn/news/312749.html

相关文章:

  • C++速通LeetCode中等第7题-和为K的子数组(巧用前缀和)
  • 视频服务器:GB28181网络视频协议
  • python使用argparse解析命令行,如何正确传入科学计数法形式的浮点数
  • 力扣100题——杂题
  • Java集合(一)
  • C++ 文件操作
  • 十、数字人IP应用方案
  • chromedriver下载与安装方法
  • react之jsx基础(2)高频使用场景
  • DEPLOT: One-shot visual language reasoning by plot-to-table translation论文阅读
  • Android14请求动态申请存储权限
  • WGCAT工单系统 v1.2.1 支持导出PDF和分享创建工单功能
  • JAVA 根据开始和结束ip,计算中间的所有ip
  • 【MySQL】MySQL和Workbench版本兼容问题
  • 力扣每日一题 公交站间的距离
  • 远程访问NAS速度慢??那是因为你没用对。。。
  • 2024年9月北京docker安装+nvidia-docker
  • Clang插件演示-直接调用AI模型定义的变量完成模型推理
  • IP Source Guard技术原理与应用
  • 如何在GitHub上克隆仓库:HTTPS、SSH和GitHub CLI的区别
  • 【机器学习(五)】分类和回归任务-AdaBoost算法-Sentosa_DSML社区版
  • 【算法题】300. 最长递增子序列-力扣(LeetCode)
  • 【资料分析】刷题日记3
  • node前端开发基本设置
  • 计算机毕业设计 公寓出租系统的设计与实现 Java实战项目 附源码+文档+视频讲解
  • 冷热电气多能互补的微能源网优化调度(含matlab代码)
  • MinIO自动化下载及部署脚本(Windows)
  • macOS Sequoia 15 发布,iPhone 镜像、密码应用程序、窗口平铺更新等带来全新体验
  • 数据中心一体化智能运维方案
  • tomcat中间件漏洞CVE-2017-12615,后台弱口令部署war包,CVE-2020-1938