Intent to open the Notification Channel settings from my app

房东的猫 提交于 2019-12-07 03:19:25

问题


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.


回答1:


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



回答2:


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


来源:https://stackoverflow.com/questions/48853948/intent-to-open-the-notification-channel-settings-from-my-app

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!