赞
踩
场景:uni-app开启移动app,如果用户没开启消息通知提示开启
因为uni-app升级到androidx,之前的android.support.v4.app.NotificationManagerCompat 已经找不到了,androidx中采用androidx.core.app.NotificationManagerCompat
var main = plus.android.runtimeMainActivity(); var pkName = main.getPackageName(); var NotificationManagerCompat = plus.android.importClass( "androidx.core.app.NotificationManagerCompat"); console.log(NotificationManagerCompat) var isEnabled = NotificationManagerCompat.from(main).areNotificationsEnabled(); //手机没有开启通知的权限 if (!isEnabled) { try{ console.log("===================") //这里写打开弹窗的逻辑,提示用户去开启 }catch(e){ console.log("------------------") console.log(e) } }
main = plus.android.runtimeMainActivity(); pkName = main.getPackageName(); uid = main.getApplicationInfo().plusGetAttribute("uid"); Intent = plus.android.importClass('android.content.Intent'); Build = plus.android.importClass("android.os.Build"); if (Build.VERSION.SDK_INT >= 26) { var 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 var intent = new Intent('android.settings.APP_NOTIFICATION_SETTINGS'); intent.putExtra("app_package", pkName); intent.putExtra("app_uid", uid); } else { //(<21)其他--跳转到该应用管理的详情页 var Settings = plus.android.importClass("android.provider.Settings"); var Uri = plus.android.importClass("android.net.Uri"); var intent = new Intent(); intent.setAction(Settings.ACTION_APPLICATION_DETAILS_SETTINGS); var uri = Uri.fromParts("package", main.getPackageName(), null); intent.setData(uri); } // 跳转到该应用的系统通知设置页 main.startActivity(intent);
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。