var main = plus.android.runtimeMainActivity();
var NotificationManagerCompat = plus.android.importClass(“androidx.core.app.NotificationManagerCompat”);
let pkName = main.getPackageName();
let packageNames = NotificationManagerCompat.from(main);
console.log(‘通知权限’, packageNames.areNotificationsEnabled())
if (!packageNames.areNotificationsEnabled()) {
uni.showModal({
title: “提示”,
content: 请打开通知权限!
,
cancelText: ‘取消’,
confirmText: ‘去设置’,
showCancel: true, // 是否显示取消按钮,默认为 true
}).then(() => {
let uid = main.getApplicationInfo().plusGetAttribute(“uid”);
let Intent = plus.android.importClass(‘android.content.Intent’);
let Build = plus.android.importClass(“android.os.Build”);
let intent = ‘’;
//android 8.0引导
if (Build.VERSION.SDK_INT >= 26) {
intent = new Intent(‘android.settings.APP_NOTIFICATION_SETTINGS’);
intent.putExtra(‘android.provider.extra.APP_PACKAGE’, pkName);
} else if (Build.VERSION.SDK_INT >= 21) { //android 5.0-7.0
intent = new Intent(‘android.settings.APP_NOTIFICATION_SETTINGS’);
intent.putExtra(“app_package”, pkName);
intent.putExtra(“app_uid”, uid);
} else { //(<21)其他–跳转到该应用管理的详情页
let Settings = plus.android.importClass(“android.provider.Settings”);
let Uri = plus.android.importClass(“android.net.Uri”);
intent = new Intent();
intent.setAction(Settings.ACTION_APPLICATION_DETAILS_SETTINGS);
let uri = Uri.fromParts(“package”, main.getPackageName(), null);
intent.setData(uri);
}
// 跳转到该应用的系统通知设置页
main.startActivity(intent);
}).catch(() => {})
}
03-22
1895
![](https://csdnimg.cn/release/blogv2/dist/pc/img/readCountWhite.png)
06-14
3683
![](https://csdnimg.cn/release/blogv2/dist/pc/img/readCountWhite.png)
11-24
5534
![](https://csdnimg.cn/release/blogv2/dist/pc/img/readCountWhite.png)