Déterminez si la notification de l'application est bloquée, un rappel contextuel et un bouton pour accéder à la page de notification ouverte correspondante

demande:

1. Après une nouvelle installation ou une mise à niveau, déterminez si le système bloque les notifications de l'application.

2. Si la notification est bloquée, une fenêtre contextuelle vous rappelant d'ouvrir la notification apparaîtra.

3. Cliquez sur le bouton "Ouvrir maintenant" dans la fenêtre pop-up pour passer à l'interface de configuration de notification de cette application correspondant au système.

Solution:

1. Déterminez si la fonction de notification de l'application de notification est bloquée. code montrer comme ci-dessous:

NotificationManagerCompat notificationManagerCompat = NotificationManagerCompat.from(this);
boolean areNotificationsEnabled = notificationManagerCompat.areNotificationsEnabled();

Remarque: cette méthode est uniquement pour Android 4.3 et supérieur

2. Accédez à la page des paramètres de notification correspondante. code montrer comme ci-dessous:

public static void goSystemNotificationSetting(Context context) {

        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {

            Uri uri = Uri.parse("package:" + context.getPackageName());
            Intent intentSet = new Intent(Settings.ACTION_APPLICATION_DETAILS_SETTINGS, uri);
            context.startActivity(intentSet);
        } else if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {

            Intent intent = new Intent();
            intent.setAction("android.settings.APP_NOTIFICATION_SETTINGS");
            intent.putExtra("app_package", context.getPackageName());
            intent.putExtra("app_uid", context.getApplicationInfo().uid);
            context.startActivity(intent);
        } else if (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:" + context.getPackageName()));
            context.startActivity(intent);
        } else {

            Intent localIntent = new Intent();
            localIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
            localIntent.setAction(Settings.ACTION_APPLICATION_DETAILS_SETTINGS);
            localIntent.setData(Uri.fromParts("package", context.getPackageName(), null));
            context.startActivity(localIntent);
        }
    }

 

 

Je suppose que tu aimes

Origine blog.csdn.net/nsacer/article/details/80350735
conseillé
Classement