Hi how can I enable/disable the notification access settings for my app automatically?
Asked
Active
Viewed 9,097 times
0
-
in the option in settings>security to allow your app to access to notifications!! – akrem Nov 13 '15 at 12:44
-
i'm reading the notification from whatsapp! – akrem Nov 13 '15 at 12:44
2 Answers
4
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.

harsh201
- 121
- 5
-
-
Its the package name of your application like com.whatsapp for WhatsApp – harsh201 Aug 16 '16 at 09:03
0
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));

Shekhar
- 254
- 2
- 10
-
The following post is more helpful: http://stackoverflow.com/questions/18212209/accessing-the-new-notification-settings-in-android-4-3-through-code – Eugene Apr 08 '16 at 13:30