Java Code Examples for org.apache.cordova.PermissionHelper#requestPermission()

The following examples show how to use org.apache.cordova.PermissionHelper#requestPermission() . 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: 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 3
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 4
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 5
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 6
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 7
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 8
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 9
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 10
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);
}