Example usage for android.content.pm PackageManager PERMISSION_DENIED

List of usage examples for android.content.pm PackageManager PERMISSION_DENIED

Introduction

In this page you can find the example usage for android.content.pm PackageManager PERMISSION_DENIED.

Prototype

int PERMISSION_DENIED

To view the source code for android.content.pm PackageManager PERMISSION_DENIED.

Click Source Link

Document

Permission check result: this is returned by #checkPermission if the permission has not been granted to the given package.

Usage

From source file:nu.yona.app.ui.YonaActivity.java

@TargetApi(Build.VERSION_CODES.M)
@Override// www  .java 2s .co  m
public void onRequestPermissionsResult(int requestCode, @NonNull String permissions[],
        @NonNull int[] grantResults) {
    Logger.loge(YonaActivity.class.getSimpleName(), "onRequestPermissionsResult");
    isToDisplayLogin = false;
    // Make sure it's our original READ_CONTACTS request
    if (requestCode == READ_EXTERNAL_STORAGE_REQUEST) {
        if (grantResults.length == 1 && grantResults[0] == PackageManager.PERMISSION_GRANTED) {
            pickImage();
        } else {
            openCaptureImage();
            super.onRequestPermissionsResult(requestCode, permissions, grantResults);
        }
    } else if (requestCode == CAMERA_REQUEST) {
        if (grantResults.length == 1 && grantResults[0] == PackageManager.PERMISSION_GRANTED) {
            pickCamera();
        } else {
            openCamera();
            super.onRequestPermissionsResult(requestCode, permissions, grantResults);
        }
    } else if (requestCode == AppConstant.READ_CONTACTS_PERMISSIONS_REQUEST) {
        for (int i = 0, len = permissions.length; i < len; i++) {
            String permission = permissions[i];
            if (grantResults[i] == PackageManager.PERMISSION_GRANTED) {
                openContactBook();
            } else if (grantResults[i] == PackageManager.PERMISSION_DENIED) {
                boolean showRationale = shouldShowRequestPermissionRationale(permission);
                if (!showRationale) {
                    allowContactPermission(getString(R.string.contact_permission),
                            getString(R.string.contact_permission_detail));
                    break;
                }
            }
        }
    } else if (requestCode == AppConstant.FILE_WRITE_PERMISSION) {
        for (int i = 0, len = permissions.length; i < len; i++) {
            String permission = permissions[i];
            if (grantResults[i] == PackageManager.PERMISSION_DENIED) {
                boolean showRationale = shouldShowRequestPermissionRationale(permission);
                if (!showRationale) {
                    allowPermission(getString(R.string.file_write_permission),
                            getString(R.string.file_write_permission_detail));
                    break;
                } else if (Manifest.permission.WRITE_EXTERNAL_STORAGE.equals(permission)) {
                    getFileWritePermission();
                    break;
                }
            } else if (grantResults[i] == PackageManager.PERMISSION_GRANTED) {
                isUserFromOnCreate = true;
            }
        }
    }
}

From source file:net.exclaimindustries.geohashdroid.activities.CentralMap.java

@Override
public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions,
        @NonNull int[] grantResults) {
    if (permissions.length <= 0 || grantResults.length <= 0)
        return;//ww w .  j  av a  2 s  .  c om

    // CentralMap will generally be handling location permissions.  So...
    if (grantResults[0] == PackageManager.PERMISSION_DENIED) {
        // Whoops.  We're sunk.  Go to the permission failure dialog thing.
        Bundle args = new Bundle();
        args.putInt(PermissionDeniedDialogFragment.TITLE, R.string.title_permission_location);
        args.putInt(PermissionDeniedDialogFragment.MESSAGE, R.string.explain_permission_location);

        PermissionDeniedDialogFragment frag = new PermissionDeniedDialogFragment();
        frag.setArguments(args);
        frag.show(getFragmentManager(), "PermissionDeniedDialog");

        mPermissionsDenied = true;
    } else {
        // Thankfully, we don't need to ask for forgiveness, as we've
        // got permissions right here!
        startListening();

        mPermissionsDenied = false;
    }

    if (mCurrentMode != null)
        mCurrentMode.permissionsDenied(mPermissionsDenied);
}