下面列出了org.apache.cordova.PermissionHelper#hasPermission ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
/**
* Check saveImage arguments and app permissions
*
* @param args JSON Array of args
* @param callbackContext callback id for optional progress reports
*
* args[0] filePath file path string to image file to be saved to gallery
*/
private void saveImageToGallery(JSONArray args, CallbackContext callback) throws JSONException {
this.filePath = args.getString(0);
this.callbackContext = callback;
Log.d("SaveImage", "SaveImage in filePath: " + filePath);
if (filePath == null || filePath.equals("")) {
callback.error("Missing filePath");
return;
}
if (PermissionHelper.hasPermission(this, WRITE_EXTERNAL_STORAGE)) {
Log.d("SaveImage", "Permissions already granted, or Android version is lower than 6");
performImageSave();
} else {
Log.d("SaveImage", "Requesting permissions for WRITE_EXTERNAL_STORAGE");
PermissionHelper.requestPermission(this, WRITE_PERM_REQUEST_CODE, WRITE_EXTERNAL_STORAGE);
}
}
private boolean checkPermissions(JSONArray args, CallbackContext callbackContext) {
if (!PermissionHelper.hasPermission(this, Manifest.permission.WRITE_EXTERNAL_STORAGE)) {
permissionRequests.put(permissionRequests.size(), new PermissionsRequest(args, callbackContext));
PermissionHelper.requestPermission(this, permissionRequests.size() - 1, Manifest.permission.WRITE_EXTERNAL_STORAGE);
return false;
}
return true;
}
/**
* 判断是否有对应权限
*/
public boolean hasPermisssion() {
for(String p : permissions)
{
if(!PermissionHelper.hasPermission(this, p))
{
return false;
}
}
return true;
}
public boolean hasPermisssion() {
for (final String p : permissions) {
if (!PermissionHelper.hasPermission(this, p)) {
return false;
}
}
return true;
}
private boolean hasReadPermission() {
return PermissionHelper.hasPermission(this, Manifest.permission.READ_EXTERNAL_STORAGE);
}
private boolean hasWritePermission() {
return PermissionHelper.hasPermission(this, Manifest.permission.WRITE_EXTERNAL_STORAGE);
}
private boolean hasReadPermission() {
return PermissionHelper.hasPermission(this, Manifest.permission.READ_EXTERNAL_STORAGE);
}
private boolean hasWritePermission() {
return PermissionHelper.hasPermission(this, Manifest.permission.WRITE_EXTERNAL_STORAGE);
}
private boolean hasReadPermission() {
return PermissionHelper.hasPermission(this, Manifest.permission.READ_EXTERNAL_STORAGE);
}
private boolean hasWritePermission() {
return PermissionHelper.hasPermission(this, Manifest.permission.WRITE_EXTERNAL_STORAGE);
}
private boolean hasReadPermission() {
return PermissionHelper.hasPermission(this, Manifest.permission.READ_EXTERNAL_STORAGE);
}
private boolean hasWritePermission() {
return PermissionHelper.hasPermission(this, Manifest.permission.WRITE_EXTERNAL_STORAGE);
}