Example usage for org.apache.cordova PermissionHelper requestPermission

List of usage examples for org.apache.cordova PermissionHelper requestPermission

Introduction

In this page you can find the example usage for org.apache.cordova PermissionHelper requestPermission.

Prototype

public static void requestPermission(CordovaPlugin plugin, int requestCode, String permission) 

Source Link

Document

Requests a "dangerous" permission for the application at runtime.

Usage

From source file:com.microsoft.aad.adal.CordovaAdalPlugin.java

License:Open Source License

private void requestBrokerPermissions() {

    // USE_CREDENTIALS and MANAGE_ACOUNTS are deprecated and not required
    if (PermissionHelper.hasPermission(this, Manifest.permission.GET_ACCOUNTS)) { // android.permission.GET_ACCOUNTS
        // already granted
        callbackContext.success();//  www  . j  a  v a 2 s .c o  m
        return;
    }

    PermissionHelper.requestPermission(this, GET_ACCOUNTS_PERMISSION_REQ_CODE,
            Manifest.permission.GET_ACCOUNTS);
}

From source file:com.tmantman.nativecamera.NativeCameraLauncher.java

License:Apache License

public void takePicture() {
    // Camera/*from ww w  .  j  a  va2 s  .c o m*/
    if (this.srcType == 1) {
        // Save the number of images currently on disk for later
        Intent intent = new Intent(this.cordova.getActivity().getApplicationContext(), CameraActivity.class);
        this.photo = createCaptureFile();
        this.imageUri = Uri.fromFile(photo);
        intent.putExtra(MediaStore.EXTRA_OUTPUT, this.imageUri);
        this.cordova.startActivityForResult((CordovaPlugin) this, intent, 1);
    } else if ((this.srcType == 0) || (this.srcType == 2)) {
        // FIXME: Stop always requesting the permission
        if (!PermissionHelper.hasPermission(this, Manifest.permission.READ_EXTERNAL_STORAGE)) {
            PermissionHelper.requestPermission(this, SAVE_TO_ALBUM_SEC,
                    Manifest.permission.READ_EXTERNAL_STORAGE);
        } else {
            this.getImage(this.srcType, this.destType, this.encodingType);
        }
    }
}

From source file:com.whamads.nativecamera.NativeCameraLauncher.java

License:Apache License

@Override
public boolean execute(String action, JSONArray args, CallbackContext callbackContext) throws JSONException {
    PluginResult.Status status = PluginResult.Status.OK;
    String result = "";
    this.callbackContext = callbackContext;
    try {/*from   www  .ja  va2  s . c  o m*/
        if (action.equals("takePicture")) {

            if (!PermissionHelper.hasPermission(this, Manifest.permission.CAMERA)) {
                PermissionHelper.requestPermission(this, 1, Manifest.permission.CAMERA);
            } else {

                this.targetHeight = 0;
                this.targetWidth = 0;
                this.mQuality = 80;
                this.targetHeight = args.getInt(4);
                this.targetWidth = args.getInt(3);
                this.mQuality = args.getInt(0);
                this.takePicture();
                PluginResult r = new PluginResult(PluginResult.Status.NO_RESULT);
                r.setKeepCallback(true);
                callbackContext.sendPluginResult(r);
            }
            return true;
        }
        return false;
    } catch (JSONException e) {
        e.printStackTrace();
        callbackContext.sendPluginResult(new PluginResult(PluginResult.Status.JSON_EXCEPTION));
        return true;
    }
}

From source file:pro.alyans.nativecamera.NativeCameraLauncher.java

License:Apache License

public void takePicture() {
    // Camera/*from w w  w  .j a v  a 2  s  . com*/
    if (this.srcType == 1) {
        if (!PermissionHelper.hasPermission(this, Manifest.permission.CAMERA)) {
            PermissionHelper.requestPermission(this, TAKE_PIC_SEC, Manifest.permission.CAMERA);
        } else {
            // Save the number of images currently on disk for later
            Intent intent = new Intent(this.cordova.getActivity().getApplicationContext(),
                    CameraActivity.class);
            this.photo = createCaptureFile();
            this.imageUri = Uri.fromFile(photo);
            intent.putExtra(MediaStore.EXTRA_OUTPUT, this.imageUri);
            this.cordova.startActivityForResult((CordovaPlugin) this, intent, 1);
        }
    } else if ((this.srcType == 0) || (this.srcType == 2)) {
        // FIXME: Stop always requesting the permission
        if (!PermissionHelper.hasPermission(this, Manifest.permission.READ_EXTERNAL_STORAGE)) {
            PermissionHelper.requestPermission(this, SAVE_TO_ALBUM_SEC,
                    Manifest.permission.READ_EXTERNAL_STORAGE);
        } else {
            this.getImage(this.srcType, this.destType, this.encodingType);
        }
    }
}