Ich habe die Kanalbenachrichtigungseinstellungen für Android 8.0 Oreo API 26 oder höher angehängt. Es gibt eine Lösung von Android 4.4, KitKat.
Verwendung für Kanalbenachrichtigungseinstellungen:
goToNotificationSettings(getString(R.string.PRIMARY_CHANNEL), mContext);
goToNotificationSettings(getString(R.string.SECONDARY_CHANNEL), mContext);
Verwendung für App-Benachrichtigungseinstellungen:
goToNotificationSettings(null, mContext)
Die Methode von goToNotificationSettings:
public void goToNotificationSettings(String channel, Context context) {
Intent intent = new Intent();
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.P) {
intent.addFlags(android.content.Intent.FLAG_ACTIVITY_NEW_TASK);
if (channel != null) {
intent.setAction(Settings.ACTION_CHANNEL_NOTIFICATION_SETTINGS);
intent.putExtra(Settings.EXTRA_CHANNEL_ID, channel);
} else {
intent.setAction(Settings.ACTION_APP_NOTIFICATION_SETTINGS);
}
intent.putExtra(Settings.EXTRA_APP_PACKAGE, context.getPackageName());
} else if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
if (channel != null) {
intent.setAction(Settings.ACTION_CHANNEL_NOTIFICATION_SETTINGS);
intent.putExtra(Settings.EXTRA_CHANNEL_ID, channel);
} else {
intent.setAction(Settings.ACTION_APP_NOTIFICATION_SETTINGS);
}
intent.putExtra(Settings.EXTRA_APP_PACKAGE, context.getPackageName());
} else if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.N_MR1) {
intent.setAction(Settings.ACTION_APP_NOTIFICATION_SETTINGS);
intent.putExtra(Settings.EXTRA_APP_PACKAGE, context.getPackageName());
} else if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP){
intent.setAction(Settings.ACTION_APP_NOTIFICATION_SETTINGS);
intent.putExtra("app_package", context.getPackageName());
intent.putExtra("app_uid", context.getApplicationInfo().uid);
} else if (Build.VERSION.SDK_INT == Build.VERSION_CODES.KITKAT) {
intent.setAction(Settings.ACTION_APPLICATION_DETAILS_SETTINGS);
intent.addCategory(Intent.CATEGORY_DEFAULT);
intent.setData(Uri.parse("package:" + context.getPackageName()));
}
context.startActivity(intent);
}