androidandroid-notificationsandroid-6.0-marshmallow

Any way to link to the Android notification settings for my app?


Is there any way I can launch an intent to get to Android's notification settings screen for my app (pictured below)? Or an easy way I can make a PreferenceScreen item that just leads here on a click?

enter image description here


Solution

  • The following will work in Android 5.0 (Lollipop) and above:

    Intent intent = new Intent();
    intent.setAction("android.settings.APP_NOTIFICATION_SETTINGS");
    intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
    
    //for Android 5-7
    intent.putExtra("app_package", getPackageName());
    intent.putExtra("app_uid", getApplicationInfo().uid);
    
    // for Android 8 and above
    intent.putExtra("android.provider.extra.APP_PACKAGE", getPackageName());
    
    startActivity(intent);
    

    Notes: This is not officially supported in Android 5-7, but it works just fine. It IS officially supported as of Android 8. This code is not backwards compatible with versions of Android before 5.0.