Intent to open the Notification Channel settings from my app
Asked Answered
G

3

19

What's the Intent that I need to send in order to open the settings of a Notification Channel that I've previously created in my app? I need to link to it from my app.

Gombach answered 18/2, 2018 at 16:31 Comment(0)
B
44

To open the notification settings for a single channel, 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);

To open the notification settings for the app in general (i.e. to see all channels), use ACTION_APP_NOTIFICATION_SETTINGS:

Intent intent = new Intent(Settings.ACTION_APP_NOTIFICATION_SETTINGS)
    .putExtra(Settings.EXTRA_APP_PACKAGE, context.getPackageName());
startActivity(intent);
Balliol answered 18/2, 2018 at 16:55 Comment(3)
how to open default notification category?Trace
any idea please help?Trace
Also check this one for support older versions than Android O and edge case of Lollipop: https://mcmap.net/q/183057/-intent-to-open-the-notification-channel-settings-from-my-appCouple
G
21

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);
}
Gibe answered 9/9, 2018 at 11:17 Comment(0)
C
9

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)
}
Couple answered 25/5, 2020 at 8:27 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.