在 uniapp 开发的 APP项目中 可以运行,其它框架没有测试过!
if (plus.os.name == 'Android') { // 判断是Android
// 获取应用主Activity实例对象
const main = plus.android.runtimeMainActivity();
// 此方法以String形式返回此实体的包名称
const pkName = main.getPackageName();
// getApplicationInfo() :返回在其清单标记中定义的应用程序名称, plusGetAttribute : 获取Java类对象的静态属性
const uid = main.getApplicationInfo().plusGetAttribute("uid");
// 导入类对象后,就可以通过.操作符直接调用对象(类对象/实例对象)的方法。 注意:导入类对象将会消耗较多的系统资源,通常不应该导入过多的类对象,可以使用plus.android.invoke()来调用未导入类实例对象的方法。
let NotificationManagerCompat = plus.android.importClass("android.support.v4.app.NotificationManagerCompat");
//android.support.v4升级为androidx
if (NotificationManagerCompat == null) {
NotificationManagerCompat = plus.android.importClass("androidx.core.app.NotificationManagerCompat");
};
// areNotificationsEnabled() 返回来自调用包的通知是否被阻止。
const areNotificationsEnabled = NotificationManagerCompat.from(main).areNotificationsEnabled();
// 未开通‘允许通知’权限,则弹窗提醒开通,并点击确认后,跳转到系统设置页面进行设置
if (!areNotificationsEnabled) {
uni.showModal({
title: '通知权限开启提醒',
content: '您还没有开启通知权限,无法接受到消息通知,请前往设置!',
confirmText: '去设置',
success: function(res) {
if (res.confirm) {
let Intent = plus.android.importClass('android.content.Intent');
const intent = new Intent('android.settings.APP_NOTIFICATION_SETTINGS'); // // APP_NOTIFICATION_SETTINGS 通知权限
intent.putExtra('android.provider.extra.APP_PACKAGE', pkName);
// 跳转到该应用的系统通知设置页
main.startActivity(intent);
};
}
});
};
}
跳转其它系统设置页 :
const intent = new Intent("android.settings.ACCESSIBILITY_SETTINGS"); //辅助功能
const intent = new Intent("android.settings.ADD_ACCOUNT_SETTINGS"); //添加账户
const intent = new Intent("android.settings.AIRPLANE_MODE_SETTINGS"); //系统设置首页
const intent = new Intent("android.settings.APN_SETTINGS"); //APN设置
const intent = new Intent("android.settings.APPLICATION_SETTINGS"); //应用管理
const intent = new Intent("android.settings.BATTERY_SAVER_SETTINGS"); //节电助手
const intent = new Intent("android.settings.BLUETOOTH_SETTINGS"); //蓝牙
const intent = new Intent("android.settings.CAPTIONING_SETTINGS"); //字幕
const intent = new Intent("android.settings.CAST_SETTINGS"); //无线显示
const intent = new Intent("android.settings.DATA_ROAMING_SETTINGS"); //移动网络
const intent = new Intent("android.settings.DATE_SETTINGS"); //日期和时间设置
const intent = new Intent("android.settings.DEVICE_INFO_SETTINGS"); //关于手机
const intent = new Intent("android.settings.DISPLAY_SETTINGS"); //显示设置
const intent = new Intent("android.settings.DREAM_SETTINGS"); //互动屏保设置
const intent = new Intent("android.settings.HARD_KEYBOARD_SETTINGS"); //实体键盘
const intent = new Intent("android.settings.HOME_SETTINGS"); //应用权限,默认应用设置,特殊权限
const intent = new Intent("android.settings.IGNORE_BATTERY_OPTIMIZATION_SETTINGS"); //忽略电池优化设置
const intent = new Intent("android.settings.INPUT_METHOD_SETTINGS"); //可用虚拟键盘设置
const intent = new Intent("android.settings.INPUT_METHOD_SUBTYPE_SETTINGS"); //安卓键盘语言设置(AOSP)
const intent = new Intent("android.settings.INTERNAL_STORAGE_SETTINGS"); //内存和存储
const intent = new Intent("android.settings.LOCALE_SETTINGS"); //语言偏好设置
const intent = new Intent("android.settings.LOCATION_SOURCE_SETTINGS"); //定位服务设置
const intent = new Intent("android.settings.MANAGE_ALL_APPLICATIONS_SETTINGS"); //所有应用
const intent = new Intent("android.settings.MANAGE_APPLICATIONS_SETTINGS"); //应用管理
const intent = new Intent("android.settings.MANAGE_DEFAULT_APPS_SETTINGS"); //与ACTION_HOME_SETTINGS相同
const intent = new Intent("android.settings.action.MANAGE_OVERLAY_PERMISSION"); //在其他应用上层显示,悬浮窗
const intent = new Intent("android.settings.MANAGE_UNKNOWN_APP_SOURCES"); //安装未知应用 安卓8.0
const intent = new Intent("android.settings.action.MANAGE_WRITE_SETTINGS"); //可修改系统设置 权限
const intent = new Intent("android.settings.MEMORY_CARD_SETTINGS"); //内存与存储
const intent = new Intent("android.settings.NETWORK_OPERATOR_SETTINGS"); //可用网络选择
const intent = new Intent("android.settings.NFCSHARING_SETTINGS"); //NFC设置
const intent = new Intent("android.settings.NFC_SETTINGS"); //网络中的 更多设置
const intent = new Intent("android.settings.ACTION_NOTIFICATION_LISTENER_SETTINGS"); //通知权限设置
const intent = new Intent("android.settings.NOTIFICATION_POLICY_ACCESS_SETTINGS"); //勿扰权限设置
const intent = new Intent("android.settings.ACTION_PRINT_SETTINGS"); //打印服务设置
const intent = new Intent("android.settings.PRIVACY_SETTINGS"); //备份和重置
const intent = new Intent("android.settings.SECURITY_SETTINGS"); //安全设置
const intent = new Intent("android.settings.SHOW_REGULATORY_INFO"); //监管信息
const intent = new Intent("android.settings.SOUND_SETTINGS"); //声音设置
const intent = new Intent("android.settings.SYNC_SETTINGS"); //添加账户设置
const intent = new Intent("android.settings.USAGE_ACCESS_SETTINGS"); //有权查看使用情况的应用
const intent = new Intent("android.settings.USER_DICTIONARY_SETTINGS"); //个人词典
const intent = new Intent("android.settings.VOICE_INPUT_SETTINGS"); //辅助应用和语音输入
const intent = new Intent("android.settings.VPN_SETTINGS"); //VPN设置
const intent = new Intent("android.settings.VR_LISTENER_SETTINGS"); //VR助手
const intent = new Intent("android.settings.WEBVIEW_SETTINGS"); //选择webview
const intent = new Intent("android.settings.WIFI_IP_SETTINGS"); //高级WLAN设置
const intent = new Intent("android.settings.WIFI_SETTINGS"); //选择WIFI,连接WIFI
参考文章: