Any Way to Link to the Android Notification Settings for My App

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

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.

Intent to open the Notification Channel settings from my app

To open the settings for a single channel, you can use ACTION_CHANNEL_NOTIFICATION_SETTINGS:

Intent intent = new Intent(Settings.ACTION_CHANNEL_NOTIFICATION_SETTINGS)
.putExtra(Settings.EXTRA_APP_PACKAGE, context.getPackageName())
.putExtra(Settings.EXTRA_CHANNEL_ID, yourChannelId);
startActivity(intent);

Using ACTION_APP_NOTIFICATION_SETTINGS will list all channels of the app:

Intent intent = new Intent(Settings.ACTION_APP_NOTIFICATION_SETTINGS)
.putExtra(Settings.EXTRA_APP_PACKAGE, context.getPackageName());
startActivity(intent);

Access application notification settings programmatically

There is no public API that will allow you to deep link into your application's notification settings directly.

You can use Settings.ACTION_APPLICATION_DETAILS_SETTINGS to deep link to your application's settings, but this will not take you directly to the notifications screen.

Any way to link to the Android notification settings for my app? has a solution that may work, but since it is not a part of the official API it is not guaranteed to work on all devices or for future versions of Android.

if there is a way to turn the "Block notificaations" on and off programatically that would be ok too

Absolutely not. Allowing an application to programmatically turn it's notifications on and off defeats the purpose of giving the user control over turning notifications on and off.

Listen for changes in Notification Settings for the app

As posted in another SO answer, API 28 added system broadcasts for ACTION_NOTIFICATION_CHANNEL_BLOCK_STATE_CHANGED and ACTION_NOTIFICATION_CHANNEL_GROUP_BLOCK_STATE_CHANGED that should suit your needs (see documentation).

Notifications Settings activity for all apps in Android Oreo

It looks like, currently it is not possible using official Android API to access Notification Settings of All apps i.e. Settings > Apps & notifications > See all <N> apps (this path from Pixel API 27) activity is not able to access.

In case of Samsung they might have their own UI customization which is one more step of difficulty to access this Activity.

Intent to open the Notification Channel settings from my app

To open the settings for a single channel, you can use ACTION_CHANNEL_NOTIFICATION_SETTINGS:

Intent intent = new Intent(Settings.ACTION_CHANNEL_NOTIFICATION_SETTINGS)
.putExtra(Settings.EXTRA_APP_PACKAGE, context.getPackageName())
.putExtra(Settings.EXTRA_CHANNEL_ID, yourChannelId);
startActivity(intent);

Using ACTION_APP_NOTIFICATION_SETTINGS will list all channels of the app:

Intent intent = new Intent(Settings.ACTION_APP_NOTIFICATION_SETTINGS)
.putExtra(Settings.EXTRA_APP_PACKAGE, context.getPackageName());
startActivity(intent);

How to add a notification settings activity to the system settings

You need to add the Intent category Notification.INTENT_CATEGORY_NOTIFICATION_PREFERENCES to the Activity you'd like to launch through your AndroidManifest. A simple example would be something like:

    <activity android:name="com.example.packagename.YourSettingsActivity" >

<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.NOTIFICATION_PREFERENCES" />
</intent-filter>
</activity>

For more information, refer to the Settings app and specifically the NotificationAppList and AppNotificationSettings fragments.

Results

example

How to launch device's notification settings for my Android app from a PreferenceScreen

For Android 5-7:
You have to call start activity from code (programmatically) because there is no way to determine uid of the app in Layout file

Intent intent = new Intent();
intent.setAction("android.settings.APP_NOTIFICATION_SETTINGS");
intent.putExtra("app_package", getPackageName());
intent.putExtra("app_uid", getApplicationInfo().uid);

For Android O up:

<intent android:action="android.settings.APP_NOTIFICATION_SETTINGS">
<extra android:name="android.provider.extra.APP_PACKAGE" android:value="your app package name" />
</intent>


Related Topics



Leave a reply



Submit