/**
* 申请权限
*/
private void requestPermission() {
List<String> permissions = new ArrayList<String>();
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
if (!(activity.checkSelfPermission(Manifest.permission.WRITE_EXTERNAL_STORAGE) == PackageManager.PERMISSION_GRANTED)) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
permissions.add(Manifest.permission.WRITE_EXTERNAL_STORAGE);
}
}
if (!(activity.checkSelfPermission(Manifest.permission.READ_EXTERNAL_STORAGE) == PackageManager.PERMISSION_GRANTED)) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
permissions.add(Manifest.permission.READ_EXTERNAL_STORAGE);
}
}
if (!(activity.checkSelfPermission(Manifest.permission.CAMERA) == PackageManager.PERMISSION_GRANTED)) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
permissions.add(Manifest.permission.CAMERA);
}
}
if (!(activity.checkSelfPermission(Manifest.permission.RECORD_AUDIO) == PackageManager.PERMISSION_GRANTED)) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
permissions.add(Manifest.permission.RECORD_AUDIO);
}
}
if (permissions.size() > 0) {
String[] pers = permissions.toArray(new String[permissions.size()]);
activity.requestPermissions(pers, REQUEST_CODED);
}
}
}
Android 6.0以上动态申请权限(代码案例)
最新推荐文章于 2024-10-16 15:49:43 发布