Android 取消蓝牙消息通知流程分析(一)

本文详细分析了在Android系统中,如何通过设置通知来取消蓝牙消息提示的过程。从用户界面操作到代码层面,涉及NotificationBackend、NotificationManagerService和RankingHelper等组件,最终将设置保存在notification_policy.xml文件中,确保系统重启后仍生效。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

设置通知

在“设置->通知”中 选择“显示系统进程” 的话,会在应用列表中看到“蓝牙共享”应用,点击进入,打开“显示时不发出提示音”。这样,当有蓝牙设备发送文件过来时,就不再有提示了。
接下来分析一下代码,当打开这个开关时,都做了什么。
首先我们可以根据这个preferece的title,找到这个preference。是在packages/apps/Settings/src/com/android/settings/notification/AppNotificationSettings.java中的mSilent,mSilent的OnPreferenceChangeListener是在AppNotificationSettings的父类NotificationSettingsBase中设置的:

...
mSilent.setChecked(silenced);
mSilent.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() {
   
   @Override
   public boolean onPreferenceChange(Preference preference, Object newValue) {
   
       final boolean silenced = (Boolean) newValue;
       final int importance =
               silenced ? Ranking.IMPORTANCE_LOW : Ranking.IMPORTANCE_UNSPECIFIED;
       mBackend.setImportance(mPkgInfo.packageName, mUid, importance);//1
       updateDependents(importance);
       return true;
   }
});
...

最重要的处理是标记1处,开关打开,importance=Ranking.IMPORTANCE_LOW(2);开关关闭,importance=Ranking.IMPORTANCE_UNSPECIFIED(-1000);此处调用了NotificationBackend.setImportance:

public boolean setImportance(String pkg, int uid, int importance) {
   
        try {
   
            sINM.setImportance(pkg, uid, importance);
            return true;
        } catch (Exception e) {
   
            Log.w(TAG, "Error calling NoMan", e);
            return false;
        }
    }

该方法最终调用的是NotificationManagerService.setImportance:

@Override
        public void setImportance(String pkg, int uid, int importance) {
   
            enforceSystemOrSystemUI("Caller not system or systemui");
            setNotificationsEnabledForPackageImpl(pkg, uid
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值