2***@qq.com
2***@qq.com
  • 发布:2018-10-13 04:06
  • 更新:2024-10-09 14:42
  • 阅读:11140

Anroid 6.0 动态权限申请代码分享

分类:Native.js
/*  
    正常权限,无需动态申请:  
        ACCESS_LOCATION_EXTRA_COMMANDS  
        ACCESS_NETWORK_STATE  
        ACCESS_NOTIFICATION_POLICY  
        ACCESS_WIFI_STATE  
        BLUETOOTH  
        BLUETOOTH_ADMIN  
        BROADCAST_STICKY  
        CHANGE_NETWORK_STATE  
        CHANGE_WIFI_MULTICAST_STATE  
        CHANGE_WIFI_STATE  
        DISABLE_KEYGUARD  
        EXPAND_STATUS_BAR  
        GET_PACKAGE_SIZE  
        INSTALL_SHORTCUT  
        INTERNET  
        KILL_BACKGROUND_PROCESSES  
        MODIFY_AUDIO_SETTINGS  
        NFC  
        READ_SYNC_SETTINGS  
        READ_SYNC_STATS  
        RECEIVE_BOOT_COMPLETED  
        REORDER_TASKS  
        REQUEST_INSTALL_PACKAGES  
        SET_ALARM  
        SET_TIME_ZONE  
        SET_WALLPAPER  
        SET_WALLPAPER_HINTS  
        TRANSMIT_IR  
        UNINSTALL_SHORTCUT  
        USE_FINGERPRINT  
        VIBRATE  
        WAKE_LOCK  
        WRITE_SYNC_SETTINGS  

    2)危险权限,需要动态申请:  
    group:android.permission-group.STORAGE  
         READ_EXTERNAL_STORAGE   
         WRITE_EXTERNAL_STORAGE  

    group:android.permission-group.CONTACTS   
         WRITE_CONTACTS   
         GET_ACCOUNTS   
         READ_CONTACTS  

    group:android.permission-group.PHONE  
         READ_CALL_LOG   
         READ_PHONE_STATE   
         CALL_PHONE   
         WRITE_CALL_LOG   
         USE_SIP   
         PROCESS_OUTGOING_CALLS   
        com.android.voicemail.permission.ADD_VOICEMAIL  

    group:android.permission-group.CALENDAR  
         READ_CALENDAR   
         WRITE_CALENDAR  

    group:android.permission-group.CAMERA  
         CAMERA  

    group:android.permissiongroup.SENSORS  
         BODY_SENSORS  

    group:android.permission-group.LOCATION  
         ACCESS_FINE_LOCATION   
         ACCESS_COARSE_LOCATION  

    group:android.permission-group.MICROPHONE  
         RECORD_AUDIO  

    group:android.permission-group.SMS  
         READ_SMS   
         RECEIVE_WAP_PUSH   
         RECEIVE_MMS   
         RECEIVE_SMS   
         SEND_SMS   
         READ_CELL_BROADCASTS  
*/  

/**  
 * Me:   
 *    cnscn <214363570@qq.com>  
 *  
 * 参考:  
 *    https://blog.csdn.net/lvyoujt/article/details/52826556  
 *    https://developer.android.com/reference/android/Manifest.permission  
 *    https://developer.android.com/reference/android/os/Build.VERSION  
 */  

function plusReady() {  
    var Build = plus.android.importClass("android.os.Build");  
    var Manifest = plus.android.importClass("android.Manifest");  
    var MainActivity = plus.android.runtimeMainActivity();  
    //var context=main.getApplicationContext(); //未用到,在此仅供参考  

    var ArrPermissions = [          
        Manifest.permission.READ_EXTERNAL_STORAGE,  
        Manifest.permission.WRITE_EXTERNAL_STORAGE,  
        Manifest.permission.CAMERA  
    ];  

    function PermissionCheck(permission) {  
        if (Build.VERSION.SDK_INT >= 23) {  
            if (MainActivity.checkSelfPermission(permission) == -1) {  
                return false;  
            }  
        }  
        return true;  
    }  

    function PermissionChecks(Arr) {  
        var HasPermission = true;  
        for (var index in Arr) {  
            var permission = Arr[index];  
            //如果此处没有权限,则是用户拒绝了  
            if (!PermissionCheck(permission)) {  
                HasPermission = false;  
                break;  
            }  
        }  
        return HasPermission;  
    }  

    function PermissionRequest(Arr) {  
        var REQUEST_CODE_CONTACT = 101;  
        if (Build.VERSION.SDK_INT >= 23) {  
            MainActivity.requestPermissions(Arr, REQUEST_CODE_CONTACT);  
        }  
    }  

    //如果没有权限,则申请  
    if (!PermissionChecks(ArrPermissions)) {  
            PermissionRequest(ArrPermissions);  
    } else { //如果拥有权限,那么干点啥吧^_^  
            //.......  
    }  
}  

if (window.plus) {  
        plusReady();  
} else {  
        document.addEventListener('plusready', plusReady, false);  
}

15 关注 分享
绝地求生 Julian jeaStone DCloud_heavensoft 段长发 3***@qq.com 1***@qq.com 菜鸡 6***@qq.com 05309 lazi 腾杨天下 t***@hotmail.com i***@foxmail.com 美乐居士

要回复文章请先登录注册

妈惹法克儿

妈惹法克儿

感谢
2024-10-09 14:42
t***@gmail.com

t***@gmail.com

已解决,感谢!
2021-03-23 10:00
x***@126.com

x***@126.com

感谢楼主
2020-09-07 11:47
千秋忆梦

千秋忆梦

回复 shiguangqi :
老哥,这个问题解决了吗
2019-11-11 22:23
8***@qq.com

8***@qq.com

回复 2***@qq.com :
我的录音也不会动态申请,哎
2019-08-28 10:35
3***@qq.com

3***@qq.com

var Build = plus.android.importClass("android.os.Build"); 这里 加载不到类 请问是什么问题 ?
2019-07-22 17:54
6***@qq.com

6***@qq.com

使用4月27日以后的sdk,直接可以用请求权限这个功能:http://www.html5plus.org/doc/zh_cn/android.html#plus.android.implements
2019-05-31 22:50
菜鸡

菜鸡

赞!
2019-04-23 13:27
CHEN

CHEN

感谢作者!
2019-04-19 11:20
coszero

coszero

回复 2***@qq.com :
作者要是找个写安卓的交流下会变得简单很多的,感谢,辛苦了
2019-04-08 17:08