Intent To Open The Notification Channel Settings From My App
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.
Solution 1:
To open the settings for a single channel, you can use ACTION_CHANNEL_NOTIFICATION_SETTINGS
:
Intentintent=newIntent(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:
Intentintent=newIntent(Settings.ACTION_APP_NOTIFICATION_SETTINGS)
.putExtra(Settings.EXTRA_APP_PACKAGE, context.getPackageName());
startActivity(intent);
Solution 2:
Here the snippets for the notification settings as well as the granular channel settings:
privatevoidopenNotificationSettings() {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
Intentintent=newIntent(Settings.ACTION_APP_NOTIFICATION_SETTINGS);
intent.putExtra(Settings.EXTRA_APP_PACKAGE, getPackageName());
startActivity(intent);
} else {
Intentintent=newIntent(Settings.ACTION_APPLICATION_DETAILS_SETTINGS);
intent.setData(Uri.parse("package:" + getPackageName()));
startActivity(intent);
}
}
@RequiresApi(26)privatevoidopenChannelSettings(String channelId) {
Intentintent=newIntent(Settings.ACTION_CHANNEL_NOTIFICATION_SETTINGS);
intent.putExtra(Settings.EXTRA_APP_PACKAGE, getPackageName());
intent.putExtra(Settings.EXTRA_CHANNEL_ID, channelId);
startActivity(intent);
}
Solution 3:
Kotlin code, supporting older versions than Android O and edge case of Lollipop:
funopenAppNotificationSettings(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)
}
Post a Comment for "Intent To Open The Notification Channel Settings From My App"