意图从我的应用程序打开通知通道设置

时间:2018-02-18 16:31:49

标签: android android-notifications android-8.0-oreo notification-channel

我需要发送哪些意图来打开我以前在我的应用中创建的通知频道的设置? 我需要它来链接我的设置活动。

3 个答案:

答案 0 :(得分:17)

要打开单个频道的设置,您可以使用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);

使用ACTION_APP_NOTIFICATION_SETTINGS会列出该应用的所有频道:

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

答案 1 :(得分:3)

Kotlin代码,支持比Android O 更低的版本以及 Lollipop 的小写字母:

sort

答案 2 :(得分:2)

以下是通知设置和粒度通道设置的摘要:

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);
}