What's the Intent that I need to send to open the settings of a Notification Channel that I've previously created in my app? I need it to link from my settings activity.
Asked
Active
Viewed 6,109 times
3 Answers
29
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);
![](../../users/profiles/559745.webp)
Floern
- 31,495
- 23
- 98
- 115
-
how to open default notification category? – Sagar Oct 16 '18 at 14:55
-
any idea please help? – Sagar Oct 17 '18 at 07:30
-
Also check this one for support older versions than Android O and edge case of Lollipop: https://stackoverflow.com/a/61998544/3101777 – Misha Akopov Aug 23 '20 at 06:43
10
Here the snippets for the notification settings as well as the granular channel settings:
private void openNotificationSettings() {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
Intent intent = new Intent(Settings.ACTION_APP_NOTIFICATION_SETTINGS);
intent.putExtra(Settings.EXTRA_APP_PACKAGE, getPackageName());
startActivity(intent);
} else {
Intent intent = new Intent(Settings.ACTION_APPLICATION_DETAILS_SETTINGS);
intent.setData(Uri.parse("package:" + getPackageName()));
startActivity(intent);
}
}
@RequiresApi(26)
private void openChannelSettings(String channelId) {
Intent intent = new Intent(Settings.ACTION_CHANNEL_NOTIFICATION_SETTINGS);
intent.putExtra(Settings.EXTRA_APP_PACKAGE, getPackageName());
intent.putExtra(Settings.EXTRA_CHANNEL_ID, channelId);
startActivity(intent);
}
![](../../users/profiles/8281994.webp)
Florian Walther
- 4,170
- 2
- 24
- 63
3
Kotlin code, supporting older versions than Android O and edge case of Lollipop:
fun openAppNotificationSettings(context: Context) {
val intent = Intent().apply {
when {
Build.VERSION.SDK_INT >= Build.VERSION_CODES.O -> {
action = Settings.ACTION_APP_NOTIFICATION_SETTINGS
putExtra(Settings.EXTRA_APP_PACKAGE, context.packageName)
}
Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP -> {
action = "android.settings.APP_NOTIFICATION_SETTINGS"
putExtra("app_package", context.packageName)
putExtra("app_uid", context.applicationInfo.uid)
}
else -> {
action = Settings.ACTION_APPLICATION_DETAILS_SETTINGS
addCategory(Intent.CATEGORY_DEFAULT)
data = Uri.parse("package:" + context.packageName)
}
}
}
context.startActivity(intent)
}
![](../../users/profiles/3101777.webp)
Misha Akopov
- 9,542
- 26
- 54
- 73