Un moyen de créer un lien vers les parameters de notification Android pour mon application?

Est-il possible de lancer une intention pour accéder à l’écran de parameters de notification d’Android pour mon application (photo ci-dessous)? Ou un moyen simple de créer un élément PreferenceScreen qui mène tout simplement en un clic?

entrer la description de l'image ici

Ce qui suit fonctionnera dans Android 5.0 (Lollipop) et ci-dessus:

Intent intent = new Intent(); intent.setAction("android.settings.APP_NOTIFICATION_SETTINGS"); //for Android 5-7 intent.putExtra("app_package", getPackageName()); intent.putExtra("app_uid", getApplicationInfo().uid); // for Android O intent.putExtra("android.provider.extra.APP_PACKAGE", getPackageName()); startActivity(intent); 

Notes: Ceci n’est pas officiellement pris en charge dans Android 5-7, mais cela fonctionne très bien. Il est officiellement pris en charge à partir d’Android O. Ce code n’est pas compatible avec les versions d’Android antérieures à la version 5.0.

J’ai fusionné la solution de Sergei et Shhp pour supporter tous les cas:

  Intent intent = new Intent(); if(android.os.Build.VERSION.SDK_INT > Build.VERSION_CODES.N_MR1){ intent.setAction("android.settings.APP_NOTIFICATION_SETTINGS"); intent.putExtra("android.provider.extra.APP_PACKAGE", context.getPackageName()); }else if(android.os.Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP){ intent.setAction("android.settings.APP_NOTIFICATION_SETTINGS"); intent.putExtra("app_package", context.getPackageName()); intent.putExtra("app_uid", context.getApplicationInfo().uid); }else { intent.setAction(Settings.ACTION_APPLICATION_DETAILS_SETTINGS); intent.addCategory(Intent.CATEGORY_DEFAULT); intent.setData(Uri.parse("package:" + context.getPackageName())); } context.startActivity(intent); 

J’ai ajouté les parameters de notification de canal pour Android 8.0 Oreo API 26 ou ultérieure. Il existe une solution à partir d’Android 4.4, KitKat.

Utilisation des parameters de notification de canal:

 // PRIMARY_CHANNEL: goToNotificationSettings(getSsortingng(R.ssortingng.PRIMARY_CHANNEL), mContext); // SECONDARY_CHANNEL: goToNotificationSettings(getSsortingng(R.ssortingng.SECONDARY_CHANNEL), mContext); 

Utilisation des parameters de notification d’application:

 goToNotificationSettings(null, mContext); 

La méthode de goToNotificationSettings:

 public void goToNotificationSettings(Ssortingng channel, Context context) { Intent intent = new Intent(); 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); } 

J’utilise ce code (kitkat et les prochaines versions):

 if (android.os.Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { Intent intent = new Intent(); intent.setAction("android.settings.APP_NOTIFICATION_SETTINGS"); intent.putExtra("app_package", getActivity().getPackageName()); intent.putExtra("app_uid", getActivity().getApplicationInfo().uid); startActivity(intent); } else if (android.os.Build.VERSION.SDK_INT == Build.VERSION_CODES.KITKAT) { Intent intent = new Intent(); intent.setAction(Settings.ACTION_APPLICATION_DETAILS_SETTINGS); intent.addCategory(Intent.CATEGORY_DEFAULT); intent.setData(Uri.parse("package:" + getActivity().getPackageName())); startActivity(intent); } 
 public static void goToNotificationSettings(Context context) { Intent intent = new Intent(); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) { intent.setAction(Settings.ACTION_APPLICATION_DETAILS_SETTINGS); intent.setData(Uri.fromParts(SCHEME, context.getPackageName(), null)); } else if (Build.VERSION.SDK_INT > Build.VERSION_CODES.N_MR1) { intent.setAction("android.settings.APP_NOTIFICATION_SETTINGS"); intent.putExtra("app_package", context.getPackageName()); } else if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { intent.setAction("android.settings.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())); } else { return; } context.startActivity(intent); }