Android Enable/Disable Notification access Automatically

六月ゝ 毕业季﹏ 提交于 2019-12-12 05:12:24

问题


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


回答1:


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);
}

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.




回答2:


I think it is not possible.You have to go settings and u have to on.You can give intent to settings like

startActivity(new Intent(Settings.ACTION_SECURITY_SETTINGS));



来源:https://stackoverflow.com/questions/33692876/android-enable-disable-notification-access-automatically

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!