org.apache.cordova.PermissionHelper Java Examples

The following examples show how to use org.apache.cordova.PermissionHelper. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: SaveImage.java    From SaveImage with MIT License 6 votes vote down vote up
/**
 * 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);
    }      
}
 
Example #2
Source File: Flashlight.java    From Flashlight-PhoneGap-Plugin with MIT License 5 votes vote down vote up
public boolean hasPermisssion() {
  for (final String p : permissions) {
    if (!PermissionHelper.hasPermission(this, p)) {
      return false;
    }
  }
  return true;
}
 
Example #3
Source File: GeolocationPlugin.java    From cordova-plugin-baidu-geolocation with MIT License 5 votes vote down vote up
/**
 * 判断是否有对应权限
 */
public boolean hasPermisssion() {
    for(String p : permissions)
    {
        if(!PermissionHelper.hasPermission(this, p))
        {
            return false;
        }
    }
    return true;
}
 
Example #4
Source File: BackgroundDownload.java    From cordova-plugin-background-download with Apache License 2.0 5 votes vote down vote up
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;
}
 
Example #5
Source File: FileUtils.java    From keemob with MIT License 4 votes vote down vote up
private boolean hasWritePermission() {
    return PermissionHelper.hasPermission(this, Manifest.permission.WRITE_EXTERNAL_STORAGE);
}
 
Example #6
Source File: Flashlight.java    From Flashlight-PhoneGap-Plugin with MIT License 4 votes vote down vote up
public void requestPermissions(int requestCode) {
  PermissionHelper.requestPermissions(this, requestCode, permissions);
}
 
Example #7
Source File: GeolocationPlugin.java    From cordova-plugin-baidu-geolocation with MIT License 4 votes vote down vote up
public void requestPermissions(int requestCode)
{
    PermissionHelper.requestPermissions(this, requestCode, permissions);
}
 
Example #8
Source File: GeolocationPlugin.java    From cordova-plugin-baidu-geolocation with MIT License 4 votes vote down vote up
/**
 * 获取对应权限
 * int requestCode Action代码
 */
public void getPermission(int requestCode){
  if(!hasPermisssion()){
    PermissionHelper.requestPermissions(this, requestCode, permissions);
  }
}
 
Example #9
Source File: FileUtils.java    From reacteu-app with MIT License 4 votes vote down vote up
private boolean hasWritePermission() {
    return PermissionHelper.hasPermission(this, Manifest.permission.WRITE_EXTERNAL_STORAGE);
}
 
Example #10
Source File: FileUtils.java    From reacteu-app with MIT License 4 votes vote down vote up
private boolean hasReadPermission() {
    return PermissionHelper.hasPermission(this, Manifest.permission.READ_EXTERNAL_STORAGE);
}
 
Example #11
Source File: FileUtils.java    From reacteu-app with MIT License 4 votes vote down vote up
private void getWritePermission(String rawArgs, int action, CallbackContext callbackContext) {
    int requestCode = pendingRequests.createRequest(rawArgs, action, callbackContext);
    PermissionHelper.requestPermission(this, requestCode, Manifest.permission.WRITE_EXTERNAL_STORAGE);
}
 
Example #12
Source File: FileUtils.java    From reacteu-app with MIT License 4 votes vote down vote up
private void getReadPermission(String rawArgs, int action, CallbackContext callbackContext) {
    int requestCode = pendingRequests.createRequest(rawArgs, action, callbackContext);
    PermissionHelper.requestPermission(this, requestCode, Manifest.permission.READ_EXTERNAL_STORAGE);
}
 
Example #13
Source File: FileUtils.java    From keemob with MIT License 4 votes vote down vote up
private void getReadPermission(String rawArgs, int action, CallbackContext callbackContext) {
    int requestCode = pendingRequests.createRequest(rawArgs, action, callbackContext);
    PermissionHelper.requestPermission(this, requestCode, Manifest.permission.READ_EXTERNAL_STORAGE);
}
 
Example #14
Source File: FileUtils.java    From keemob with MIT License 4 votes vote down vote up
private boolean hasReadPermission() {
    return PermissionHelper.hasPermission(this, Manifest.permission.READ_EXTERNAL_STORAGE);
}
 
Example #15
Source File: FileUtils.java    From keemob with MIT License 4 votes vote down vote up
private void getWritePermission(String rawArgs, int action, CallbackContext callbackContext) {
    int requestCode = pendingRequests.createRequest(rawArgs, action, callbackContext);
    PermissionHelper.requestPermission(this, requestCode, Manifest.permission.WRITE_EXTERNAL_STORAGE);
}
 
Example #16
Source File: FileUtils.java    From keemob with MIT License 4 votes vote down vote up
private void getReadPermission(String rawArgs, int action, CallbackContext callbackContext) {
    int requestCode = pendingRequests.createRequest(rawArgs, action, callbackContext);
    PermissionHelper.requestPermission(this, requestCode, Manifest.permission.READ_EXTERNAL_STORAGE);
}
 
Example #17
Source File: FileUtils.java    From keemob with MIT License 4 votes vote down vote up
private boolean hasWritePermission() {
    return PermissionHelper.hasPermission(this, Manifest.permission.WRITE_EXTERNAL_STORAGE);
}
 
Example #18
Source File: FileUtils.java    From keemob with MIT License 4 votes vote down vote up
private boolean hasReadPermission() {
    return PermissionHelper.hasPermission(this, Manifest.permission.READ_EXTERNAL_STORAGE);
}
 
Example #19
Source File: FileUtils.java    From keemob with MIT License 4 votes vote down vote up
private void getWritePermission(String rawArgs, int action, CallbackContext callbackContext) {
    int requestCode = pendingRequests.createRequest(rawArgs, action, callbackContext);
    PermissionHelper.requestPermission(this, requestCode, Manifest.permission.WRITE_EXTERNAL_STORAGE);
}
 
Example #20
Source File: FileUtils.java    From keemob with MIT License 4 votes vote down vote up
private void getReadPermission(String rawArgs, int action, CallbackContext callbackContext) {
    int requestCode = pendingRequests.createRequest(rawArgs, action, callbackContext);
    PermissionHelper.requestPermission(this, requestCode, Manifest.permission.READ_EXTERNAL_STORAGE);
}
 
Example #21
Source File: FileUtils.java    From keemob with MIT License 4 votes vote down vote up
private boolean hasWritePermission() {
    return PermissionHelper.hasPermission(this, Manifest.permission.WRITE_EXTERNAL_STORAGE);
}
 
Example #22
Source File: FileUtils.java    From keemob with MIT License 4 votes vote down vote up
private boolean hasReadPermission() {
    return PermissionHelper.hasPermission(this, Manifest.permission.READ_EXTERNAL_STORAGE);
}
 
Example #23
Source File: FileUtils.java    From keemob with MIT License 4 votes vote down vote up
private void getWritePermission(String rawArgs, int action, CallbackContext callbackContext) {
    int requestCode = pendingRequests.createRequest(rawArgs, action, callbackContext);
    PermissionHelper.requestPermission(this, requestCode, Manifest.permission.WRITE_EXTERNAL_STORAGE);
}