dhkim1027
7/11/2017 - 1:11 AM

Android Enable/Disable Notification access Automatically - Note that the application needs to be a System application or signed with the sam

Android Enable/Disable Notification access Automatically

  • 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. https://stackoverflow.com/questions/33692876/android-enable-disable-notification-access-automatically

  • reference packages/apps/Settings/src/com/android/settings/notification/NotificationAccessSettings.java packages/apps/Settings/src/com/android/settings/notification/ServiceLisjava packages/apps/Settings/src/com/android/settings/notification/ManagedServtings.java

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