1. github地址:https://github.com/NeoLSN/cordova-plugin-android-permissions/
2. 安装插件:cordova plugin add cordova-plugin-android-permissions
3. 可获取的权限列表
4. API方法:var permissions = cordova.plugins.permissions
- checkPermission(permission, successCallback, errorCallback):检查是否有权限
- hasPermission(permission, successCallback, errorCallback):检查是否有一个或多个权限(API已过时)
- requestPermission(permission, successCallback, errorCallback):获取单一权限
- requestPermissions(permissions, successCallback, errorCallback):获取多个权限
5. Vue App中可以直接调用如下js例子获取权限
export function checkPermission() { var permissions = cordova.plugins.permissions; //定义需要获取的手机权限List var list = [ permissions.WRITE_EXTERNAL_STORAGE, permissions.ACCESS_FINE_LOCATION, permissions.CAMERA ]; //检查权限 permissions.hasPermission(list, function (s) { //检查成功 console.log("s===" + s); checking(s, list, permissions); }, function (error) { //检查失败 console.log("rror===" + error); } ); } function checking(s, permList, permissions) { //hasPermission 验证app是否有权限 if (!s.hasPermission) { //没有权限 调用申请 permissions.requestPermissions( permList, function (succ) { if (succ.hasPermission) { //申请成功 console.log("申请成功"); } else { //申请失败 console.log("申请失败"); } }, function (error) { console.log("申请失败:" + JSON.stringify(error)); } ); } else { //拥有权限 console.log("拥有权限"); } }
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)