Android自动启用/禁用通知访问 [英] Android Enable/Disable Notification access Automatically

查看:726
本文介绍了Android自动启用/禁用通知访问的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我如何启用/禁用我的通知访问设置 应用自动?

Hi how can I enable/disable the notification access settings for my app automatically?

推荐答案

可以使用以下代码完成:

It can be done using following code:

ContentResolver cr = context.getContentResolver();
String setting = Settings.Secure.ENABLED_NOTIFICATION_LISTENERS;
String permissionString = Settings.Secure.getString(cr, setting);
if(permissionString == null || !permissionString.contains("com.abc.xyz"))
{
    ComponentName analytics = new ComponentName("com.abc.xyz", "com.abc.xyz.LMN");
    if(permissionString == null)
        permissionString = "";
    else
        permissionString += ":";
    permissionString += analytics.flattenToString();
    Settings.Secure.putString(cr, setting, permissionString);
}

请注意,该应用程序必须是系统应用程序,或使用框架res apk使用的相同密钥进行签名,以便在Setting.Secure数据库中进行写入.

Note that the application needs to be a System application or signed with the same key used by framework res apk in order write in Setting.Secure database.

这篇关于Android自动启用/禁用通知访问的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆