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

【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.lryc.cn/news/442179.html

相关文章:

  • MySQL索引测试
  • 【软件设计】常用设计模式--观察者模式
  • 东北非国企就职体验
  • 经典sql题(二)求连续登录最多天数用户
  • A. Closest Point
  • 沟通更高效:微信群转移至企业微信操作攻略!
  • 计算机毕业设计 基于Python Django的旅游景点数据分析与推荐系统 Python+Django+Vue 前后端分离 附源码 讲解 文档
  • 关于安卓App自动化测试的一些想法
  • Bigemap GIS Office 2024注册机 全能版地图下载软件
  • 秦时明月6.2魔改版+GM工具+虚拟机一键端
  • firewalld实现NAT端口转发
  • 中国电子学会202309青少年软件编程(Python)等级考试试卷(二级)真题
  • 第四天旅游线路预览——从贾登峪到喀纳斯景区入口(贾登峪游客服务中心)
  • 个人常用命令
  • 如何根据协议请求去捕捉在个文件中发出去的
  • Lombok -----此java库 常用的注解及其功能总结
  • 纯前端表格导出Excel
  • sourceTree保姆级教程7:(合并某次提交)
  • JVM面试知识点手册
  • Vue3.0组合式API:使用reactive()、ref()创建响应式代理对象
  • kubernetes调度2
  • Android中如何处理运行时权限?
  • 【PyCharm】PyCharm:让开发者效率倍增的编程利器
  • Spring Boot- 配置中心问题
  • 字符串专题-1
  • Unsupervised Deep Representation Learning for Real-Time Tracking
  • 第二讲 数据结构
  • docker部署excalidraw画图工具
  • 5G技术对IT行业的影响及未来发展
  • 字节跳动的微服务独家面经