How do I detect application notification permissions?

In general, there is no notification management in Api 19, which is enabled by default. Api 19 — 24 adds notification management functionality, but does not open the interface to check whether notifications are enabled, so developers can only use reflection to obtain permission values. Above Api 24, NotificationManager provides the areNotificationsEnabled () method to detect notification permissions. In 24.1.0, areNotificationsEnabled () is enabled. Values below 19 return true by default,19-24 return the corresponding reflection value, and above 24 use native NotificationManager.


Special case is part of the domestic machine, joined the notification related custom function, the developer is out of control or detection, completely blind. Such as whether the following notification is displayed in the status bar administration.

NotificationManagerCompat.from(context).areNotificationsEnabled() 
Copy the code

It can be adapted to most models except some domestic machines. Special models can not be temporarily, there are friends who know how to ask for information.

How to jump to the notification Permission Settings page?

It also depends on the API version and model.

API version

> = 21:

// After 21, go directly to the Notification bar permission setting page
if (android.os.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);
        }
Copy the code

9 < =, < 21:

// 9-21, you can only jump to app details page
else if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.GINGERBREAD){
            intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
            intent.setAction(Settings.ACTION_APPLICATION_DETAILS_SETTINGS);
            intent.setData(Uri.fromParts("package", context.getPackageName(), null));
        } 
Copy the code

The < 9:

//9 The following app details page
else if(Build.VERSION.SDK_INT < Build.VERSION_CODES.GINGERBREAD){
            intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
            intent.setAction(Intent.ACTION_VIEW);
            intent.setClassName("com.android.settings"."com.android.settings.InstalledAppDetails");
            intent.putExtra("com.android.settings.ApplicationPkgName", context.getPackageName());
        }
Copy the code

models

Some domestic machines are to provide their own permission manager software management notice permissions, for these machines, as far as possible to jump to the corresponding permission manager page. Some of the vivo:

 // Click the Settings icon > Accelerate whitelist > My App
        // Go to Software Management > Software Management Permissions > Software > My App > Trust this software
        Intent appIntent = context.getPackageManager().getLaunchIntentForPackage("com.iqoo.secure");
        if(appIntent ! =null){
            Log.i("isPushEnable"."start1");
            context.startActivity(appIntent);
            return;
        }
Copy the code

Part of the oppo:

// Oppo click the Settings icon > App Rights Management > Manage by App > My App > I Trust this App
        // Go to Permission Privacy > Self-launch Management > My App
        appIntent = context.getPackageManager().getLaunchIntentForPackage("com.oppo.safe");
        if(appIntent ! =null){
            Log.i("isPushEnable"."start2");
            context.startActivity(appIntent);
            return;
        }
Copy the code

Other models to be tested to supplement… Jump over business NotificationPageHelper I collection has become a small tool, after installation NotificationPageHelper. Open (the Context Context).

Reference:

  1. areNotificationsEnabled
  2. Android 4.1: How to check notifications are disabled for the application?
  3. How does Android jump directly to the system permission setting page through a button in the app