赞
踩
- var androidPermissions = {
- camera: "android.permission.CAMERA", // 摄像头权限
- location: "android.permission.ACCESS_FINE_LOCATION", // 位置权限
- calendar: {
- read: "android.permission.READ_CALENDAR", // // 日历读取权限
- write: "android.permission.WRITE_CALENDAR", // // 日历写入权限
- },
- storage: {
- read: "android.permission.READ_EXTERNAL_STORAGE", // 存储读取权限
- write: "android.permission.WRITE_EXTERNAL_STORAGE", // 存储写入权限
- },
- record: "android.permission.RECORD_AUDIO", // 麦克风权限
- contact: {
- read: "android.permission.READ_CONTACTS", // 联系人读取权限
- write: "android.permission.WRITE_CONTACTS", // 联系人写入权限
- },
- sms: {
- read: "android.permission.READ_SMS", // 短信读取权限
- send: "android.permission.SEND_SMS", //短信发送权限
- receive: "android.permission.RECEIVE_SMS", // 短信接收权限
- },
- state: "android.permission.READ_PHONE_STATE", // 手机识别码权限
- phone: "android.permission.CALL_PHONE", // 拨打电话权限
- log: "android.permission.READ_CALL_LOG", // 通话记录权限
- };
-
- export default {
- onLaunch: function() {
- console.log('App Launch')
- let _this = this;
- // 获取app的权限状态数据
- let MainActivity = plus.android.runtimeMainActivity();
- let PermissionCheck = MainActivity.checkSelfPermission('android.permission.READ_EXTERNAL_STORAGE')
- console.log('MainActivity:', JSON.stringify(PermissionCheck))
- // PermissionCheck为0:有权限,为-1:没有权限
- if (PermissionCheck != 0) {
- uni.showModal({
- title: '提示',
- content: '应用保存运行状态等信息,需要获取读写手机存储(系统提示为访问设备上的照片、媒体内容和文件)权限,请允许。',
- // showCancel: false, // 不显示取消按钮
- success(res) {
- if (res.confirm) {
- _this.androidPermissionCheck('storage')
- }
- }
- });
- }
- },
- onShow: function() {
- console.log('App Show')
- },
- onHide: function() {
- console.log('App Hide')
- },
- methods: {
- getPermissionList(permissionID) {
- const id = androidPermissions[permissionID];
- const list = [];
- if (typeof id == "string") {
- list[0] = id;
- } else {
- for (let key in id) {
- list.push(id[key]);
- }
- }
- return list;
- },
- androidPermissionCheck(permissionID) {
- return new Promise((resolve, reject) => {
- if (plus) {
- let ids = this.getPermissionList(permissionID);
- // 调用plus.android.requestPermissions后就默认获取到了手机权限
- plus.android.requestPermissions(
- ids,
- function(result) {
- console.log('')
- let res = 0;
- for (let i = 0; i < result.granted.length; i++) {
- let permission = result.granted[i];
- console.log("已获取的权限:", permission);
- res = 1;
- }
- for (let i = 0; i < result.deniedPresent.length; i++) {
- let permission = result.deniedPresent[i];
- console.log("本次已拒绝的权限:", permission);
- res = 0;
- }
- for (let i = 0; i < result.deniedAlways.length; i++) {
- let permission = result.deniedAlways[i];
- console.log("永久拒绝的权限:", permission);
- res = -1;
- }
- resolve({
- code: 1,
- data: res,
- });
- },
- (error) => {
- reject({
- code: 2,
- data: `code:${error.code},msg:${error.message}!`,
- });
- }
- );
- }
- });
- }
- }
- }
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。