Android使用easypermission动态获取权限

第一步,在gradle文件中添加如下依赖:

compile 'pub.devrel:easypermissions:0.2.1'
然后就可以使用了:

private void initPermission() {
       String[] perms = {Manifest.permission.CALL_PHONE
               , Manifest.permission.WRITE_EXTERNAL_STORAGE
               , Manifest.permission.READ_EXTERNAL_STORAGE};

       if (EasyPermissions.hasPermissions(this, perms)) {
           // Already have permission, do the thing
           // ...
       } else {
           // Do not have permissions, request them now
           EasyPermissions.requestPermissions(this, "因为功能需要使用相关权限,请允许",
                   100, perms);
       }
}


你可能感兴趣的:(个人笔记)