demand:
1. After a new or upgraded installation, determine whether the system blocks App notifications.
2. If the notification is blocked, a pop-up window reminding you to open the notification will pop up.
3. Click the "Open Now" button in the pop-up window to jump to the notification setting interface of this App corresponding to the system.
Solution:
1. Determine whether the notification function of the notification App is blocked. code show as below:
NotificationManagerCompat notificationManagerCompat = NotificationManagerCompat.from(this);
boolean areNotificationsEnabled = notificationManagerCompat.areNotificationsEnabled();
Note: This method is only for Android4.3 and above
2. Jump to the corresponding notification setting page. code show as below:
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);
}
}