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:com.odoo.core.tools.permissions.DevicePermissionHelper.java

public boolean hasPermission(String permission) {
    int permissionCheck = ActivityCompat.checkSelfPermission(mActivity, permission);
    switch (permissionCheck) {
    case PackageManager.PERMISSION_GRANTED:
        return true;
    case PackageManager.PERMISSION_DENIED:
        return false;
    }//from   w  w w .  j  ava2 s. c om
    return false;
}

From source file:fr.arnaudguyon.perm.Perm.java

/**
 *
 * @return true if the Permission is already Denied
 *///from   www .j a  v a2  s .c  om
public boolean isDenied() {
    return ((ContextCompat.checkSelfPermission(mActivity, mName) == PackageManager.PERMISSION_DENIED)
            && ActivityCompat.shouldShowRequestPermissionRationale(mActivity, mName));
}

From source file:com.pimp.companionforband.fragments.extras.CameraActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_camera);

    int permissionCheck = ContextCompat.checkSelfPermission(CameraActivity.this, Manifest.permission.CAMERA);

    if (permissionCheck == PackageManager.PERMISSION_DENIED) {
        Toast.makeText(CameraActivity.this, getString(R.string.camera_permission), Toast.LENGTH_LONG).show();
        startActivity(new Intent(getApplicationContext(), MainActivity.class));
        return;//from   w ww.j av  a 2 s  .c o m
    }

    surfaceView = (SurfaceView) findViewById(R.id.surfaceView);
    surfaceHolder = surfaceView.getHolder();

    surfaceHolder.addCallback(this);
    surfaceHolder.setType(SurfaceHolder.SURFACE_TYPE_PUSH_BUFFERS);

    SharedPreferences s = getApplicationContext().getSharedPreferences("MyPrefs", 0);
    final String location = s.getString("pic_location", "/storage/emulated/0/CompanionForBand/Camera");

    jpegCallback = new Camera.PictureCallback() {

        @Override
        public void onPictureTaken(byte[] data, Camera camera) {
            FileOutputStream outStream = null;
            try {
                File file = new File(location);
                if (!file.exists() && !file.isDirectory())
                    file.mkdirs();

                outStream = new FileOutputStream(
                        location + File.separator + System.currentTimeMillis() + ".jpg");

                outStream.write(data);
                outStream.close();

                Intent scan = new Intent(Intent.ACTION_MEDIA_SCANNER_SCAN_FILE);
                Uri uri = Uri.fromFile(file);
                scan.setData(uri);
                sendBroadcast(scan);
            } catch (FileNotFoundException e) {
                e.printStackTrace();
            } catch (IOException e) {
                e.printStackTrace();
            } finally {
            }

            Toast.makeText(getApplicationContext(), getString(R.string.picture_saved) + " " + location,
                    Toast.LENGTH_SHORT).show();
            refreshCamera();
        }
    };
}

From source file:com.hiqes.andele.RequestOwnerSupportFragment.java

@TargetApi(23)
@Override/*  w  w w .  j ava2s  .  com*/
public int checkSelfPermission(String permission) {
    int ret = PackageManager.PERMISSION_GRANTED;

    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
        Fragment frag = getFragment();

        if (frag == null) {
            //  The Fragment has been garbage collected, should NOT
            //  happen but fail gracefully with a log
            Log.e(TAG, "checkSelfPermission: Fragment no long valid, assume DENIED");
            ret = PackageManager.PERMISSION_DENIED;
        } else {
            ret = frag.getActivity().checkSelfPermission(permission);
        }
    }

    return ret;
}

From source file:org.apache.cordova.geolocation.Geolocation.java

public void onRequestPermissionResult(int requestCode, String[] permissions, int[] grantResults)
        throws JSONException {
    PluginResult result;/*from w  w  w .  j  ava  2  s.  co  m*/
    //This is important if we're using Cordova without using Cordova, but we have the geolocation plugin installed
    if (context != null) {
        for (int r : grantResults) {
            if (r == PackageManager.PERMISSION_DENIED) {
                LOG.d(TAG, "Permission Denied!");
                result = new PluginResult(PluginResult.Status.ILLEGAL_ACCESS_EXCEPTION);
                context.sendPluginResult(result);
                return;
            }

        }
        result = new PluginResult(PluginResult.Status.OK);
        context.sendPluginResult(result);
    }
}

From source file:org.sufficientlysecure.keychain.ui.keyview.presenter.SystemContactPresenter.java

public void startLoader(LoaderManager loaderManager) {
    if (ContextCompat.checkSelfPermission(context,
            Manifest.permission.READ_CONTACTS) == PackageManager.PERMISSION_DENIED) {
        Log.w(Constants.TAG, "loading linked system contact not possible READ_CONTACTS permission denied!");
        view.hideLinkedSystemContact();//from w  ww . j ava2s .c om
        return;
    }

    Bundle linkedContactData = new Bundle();

    // initialises loader for contact query so we can listen to any updates
    loaderManager.restartLoader(loaderId, linkedContactData, this);
}

From source file:com.yanzhenjie.album.mvp.BaseActivity.java

private static boolean isGrantedResult(int... grantResults) {
    for (int result : grantResults) {
        if (result == PackageManager.PERMISSION_DENIED)
            return false;
    }/*from w w  w . j  a  va 2s. c om*/
    return true;
}

From source file:com.pddstudio.talkdemo.MainActivity.java

private void requestPermission() {
    if (ContextCompat.checkSelfPermission(this,
            Manifest.permission.RECORD_AUDIO) == PackageManager.PERMISSION_DENIED) {
        ActivityCompat.requestPermissions(this, new String[] { Manifest.permission.RECORD_AUDIO }, 42);
    }/*from  w  ww.java  2  s. c om*/
}

From source file:uk.ac.horizon.artcodes.Artcodes.java

public void onRequestPermissionResult(int requestCode, String[] permissions, int[] grantResults)
        throws JSONException {
    for (int grantResult : grantResults) {
        if (grantResult == PackageManager.PERMISSION_DENIED) {
            callbackContext.sendPluginResult(new PluginResult(PluginResult.Status.ERROR, "Permission Error"));
            return;
        }//from  ww  w  .j  a v  a2 s  .co  m
    }
    scanArtcode();
}

From source file:de.wolfgang_popp.shoppinglist.activity.SettingsFragment.java

private void requestExternalStoragePermission() {
    int result = ContextCompat.checkSelfPermission(getActivity(), "android.permission.WRITE_EXTERNAL_STORAGE");
    if (result == PackageManager.PERMISSION_DENIED) {
        FragmentCompat.requestPermissions(this, new String[] { "android.permission.WRITE_EXTERNAL_STORAGE" },
                REQUEST_CODE_EXT_STORAGE);
    }/*from  w  w w  . j a v a 2s  .com*/
}