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);
       }
}


發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章