Android判断通知栏是否可用

Android大约 1090 字

判断通知栏是否可用

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

跳转到app通知管理界面

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);

或者

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", getPackageName());
    intent.putExtra("app_uid", 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:" + getPackageName()));
    startActivity(intent);
}
阅读 335 · 发布于 2019-04-12

————        END        ————

扫描下方二维码关注公众号和小程序↓↓↓

昵称:
随便看看换一批