Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Access application notification settings programmatically [duplicate]

In an Android app, I have a button that I want to have the functionality of opening the App Notification settings (in Android settings).

Screenshot of Android's notification settings for the Camera application

I can open the Android settings with this

startActivityForResult(new Intent(android.provider.Settings.ACTION_SETTINGS), 0);

but I want to open directly on my app notification settings

Alternative

If there is a way to turn the "Block notifications" on and off programmatically that would be ok too.

like image 869
Thought Avatar asked Jun 30 '16 13:06

Thought


1 Answers

I know this is an old question, but for those finding it in the future: as of Oreo (API level 26) there is now an official deeplink Intent for a specific app's notification settings.

Intent settingsIntent = new Intent(Settings.ACTION_APP_NOTIFICATION_SETTINGS)
        .addFlags(Intent.FLAG_ACTIVITY_NEW_TASK)
        .putExtra(Settings.EXTRA_APP_PACKAGE, getPackageName())
        .putExtra(Settings.EXTRA_CHANNEL_ID, MY_CHANNEL_ID);
startActivity(settingsIntent);

The EXTRA_CHANNEL_ID parameter is optional, and according to the docs, will "highlight that channel." FWIW, as of Android 8.1, I can't see that it makes any difference. If you are adding this parameter, ensure your Action is ACTION_CHANNEL_NOTIFICATION_SETTINGS.

like image 185
Sterling Avatar answered Sep 24 '22 01:09

Sterling