You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
84 lines
2.8 KiB
84 lines
2.8 KiB
<script> |
|
export default { |
|
onLaunch: function() { |
|
console.log('App Launch') |
|
// #ifdef APP-PLUS |
|
this.getPermis() |
|
// #endif |
|
}, |
|
onShow: function() { |
|
console.log('App Show') |
|
}, |
|
onHide: function() { |
|
console.log('App Hide') |
|
}, |
|
methods: { |
|
// 判断通知权限 |
|
getPermis() { |
|
console.log(plus.os.name) |
|
var main = plus.android.runtimeMainActivity(); |
|
var pkName = main.getPackageName(); |
|
var uid = main.getApplicationInfo().plusGetAttribute("uid"); |
|
var NotificationManagerCompat = plus.android.importClass("android.support.v4.app.NotificationManagerCompat"); |
|
console.log('plus====', NotificationManagerCompat, uid) |
|
|
|
//android.support.v4升级为androidx |
|
if (NotificationManagerCompat == null) { |
|
NotificationManagerCompat = plus.android.importClass("androidx.core.app.NotificationManagerCompat"); |
|
} |
|
console.log('plus', NotificationManagerCompat) |
|
var areNotificationsEnabled = NotificationManagerCompat.from(main).areNotificationsEnabled(); |
|
// 未开通‘允许通知’权限,则弹窗提醒开通,并点击确认后,跳转到系统设置页面进行设置 |
|
console.log('areNotificationsEnabled', areNotificationsEnabled) |
|
if (!areNotificationsEnabled) { |
|
uni.showModal({ |
|
title: '通知权限开启提醒', |
|
content: '您还没有开启通知权限,无法接受到消息通知,请前往设置!', |
|
showCancel: false, |
|
confirmText: '去设置', |
|
success: function(res) { |
|
if (res.confirm) { |
|
var Intent = plus.android.importClass('android.content.Intent'); |
|
var Build = plus.android.importClass("android.os.Build"); |
|
//android 8.0引导 |
|
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)其他--跳转到该应用管理的详情页 |
|
intent.setAction(Settings.ACTION_APPLICATION_DETAILS_SETTINGS); |
|
var uri = Uri.fromParts("package", mainActivity.getPackageName(), null); |
|
intent.setData(uri); |
|
} |
|
// 跳转到该应用的系统通知设置页 |
|
main.startActivity(intent); |
|
} |
|
} |
|
}); |
|
} |
|
}, |
|
} |
|
} |
|
</script> |
|
|
|
<style lang="scss"> |
|
/*每个页面公共css */ |
|
@import '@/uni_modules/uni-scss/index.scss'; |
|
/* #ifndef APP-NVUE */ |
|
@import '@/static/customicons.css'; |
|
|
|
// 设置整个项目的背景色 |
|
page { |
|
background-color: #f5f5f5; |
|
} |
|
|
|
/* #endif */ |
|
.example-info { |
|
font-size: 14px; |
|
color: #333; |
|
padding: 10px; |
|
} |
|
</style> |