废话不多 直接上代码:
/**
* 检查通知权限
*/
private void checkNotification() {
if (Build.VERSION.SDK_INT >= 19) {
if (!NotificationManagerCompat.from(this).areNotificationsEnabled()) {
final AlertDialog.Builder normalDialog =
new AlertDialog.Builder(MainActivity.this);
// normalDialog.setIcon(R.drawable.icon_dialog);
normalDialog.setTitle("提示");
normalDialog.setMessage("您还没有开启通知管理权限,将无法接收到推送信息,是否开启?");
normalDialog.setPositiveButton("确定",
new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
Intent localIntent = new Intent();
localIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
if (Build.VERSION.SDK_INT >= 9) {
localIntent.setAction("android.settings.APPLICATION_DETAILS_SETTINGS");
localIntent.setData(Uri.fromParts("package", MainActivity.this.getPackageName(), null));
} else if (Build.VERSION.SDK_INT <= 8) {
localIntent.setAction(Intent.ACTION_VIEW);
localIntent.setClassName("com.android.settings",
"com.android.settings.InstalledAppDetails");
localIntent.putExtra("com.android.settings.ApplicationPkgName",
MainActivity.this.getPackageName());
}
startActivity(localIntent);
}
});
normalDialog.setNegativeButton("取消",
new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
}
});
// 显示对话框
normalDialog.show();
}
}
}