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

Intent to open the Notification Channel settings from my app

我需要发送什么 Intent 才能打开我之前在我的应用程序中创建的通知通道的设置? 我需要它 link 从我的设置 activity.

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

这里是通知设置和精细频道设置的片段:

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

Kotlin 代码,支持比 Android O 更旧的版本和 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)
}