Example usage for android.content.pm PackageManager PERMISSION_GRANTED

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

Introduction

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

Prototype

int PERMISSION_GRANTED

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

Click Source Link

Document

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

Usage

From source file:cl.gisred.android.RepartoActivity.java

@Override
public void onRequestPermissionsResult(int requestCode, String permissions[], int[] grantResults) {
    switch (requestCode) {
    case Util.REQUEST_ACCESS_FINE_LOCATION: {
        // If request is cancelled, the result arrays are empty.
        if (grantResults.length > 0 && grantResults[0] == PackageManager.PERMISSION_GRANTED) {

            // permission was granted, yay! Do the
            // contacts-related task you need to do.

            setStateGPS();//from  w  w w . ja v  a2s .c  o m

        } else {

            // permission denied, boo! Disable the
            // functionality that depends on this permission.

            //SIN PERMISOS
        }
        break;
    }

    // other 'case' lines to check for other
    // permissions this app might request
    }
}

From source file:cl.gisred.android.RegEquipoActivity.java

private void verifPermisos() {
    if (ContextCompat.checkSelfPermission(RegEquipoActivity.this,
            Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED) {

        // Should we show an explanation?
        if (ActivityCompat.shouldShowRequestPermissionRationale(RegEquipoActivity.this,
                Manifest.permission.ACCESS_FINE_LOCATION)) {

        } else {/* ww  w .j ava  2s.co  m*/
            // No explanation needed, we can request the permission.

            ActivityCompat.requestPermissions(RegEquipoActivity.this,
                    new String[] { Manifest.permission.ACCESS_FINE_LOCATION },
                    Util.REQUEST_ACCESS_FINE_LOCATION);
        }
    } else {
        initGeoposition();
    }
}

From source file:com.zertinteractive.wallpaper.MainActivity.java

@Override
public void onRequestPermissionsResult(int requestCode, String[] permissions, int[] grantResults) {
    if (requestCode == RC_PERMISSION_WRITE_EXTERNAL_STORAGE) {
        if (grantResults.length == 1 && grantResults[0] == PackageManager.PERMISSION_GRANTED) {
            // We can now safely use the API we requested access to
        } else {//from   ww  w .  j  ava2  s  .  co m
            // Permission was denied or request was cancelled
            finish();
        }
    }
}

From source file:cl.gisred.android.MicroMedidaActivity.java

private void verifPermisos() {
    if (ContextCompat.checkSelfPermission(MicroMedidaActivity.this,
            Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED) {

        // Should we show an explanation?
        if (ActivityCompat.shouldShowRequestPermissionRationale(MicroMedidaActivity.this,
                Manifest.permission.ACCESS_FINE_LOCATION)) {

        } else {/*ww  w .  j  a va  2  s.  c o m*/
            // No explanation needed, we can request the permission.

            ActivityCompat.requestPermissions(MicroMedidaActivity.this,
                    new String[] { Manifest.permission.ACCESS_FINE_LOCATION },
                    Util.REQUEST_ACCESS_FINE_LOCATION);
        }
    } else {
        initGeoposition();
    }
}

From source file:com.almalence.opencam.ApplicationScreen.java

@TargetApi(23)
public void checkStoragePermission() {
    if (ContextCompat.checkSelfPermission(this,
            Manifest.permission.WRITE_EXTERNAL_STORAGE) != PackageManager.PERMISSION_GRANTED
            || ContextCompat.checkSelfPermission(this,
                    Manifest.permission.READ_EXTERNAL_STORAGE) != PackageManager.PERMISSION_GRANTED) {
        storagePermissionGranted = false;
        // Should we show an explanation?
        if (ActivityCompat.shouldShowRequestPermissionRationale(this,
                Manifest.permission.WRITE_EXTERNAL_STORAGE)
                || ActivityCompat.shouldShowRequestPermissionRationale(this,
                        Manifest.permission.READ_EXTERNAL_STORAGE)) {
            // Show an explanation to the user *asynchronously* -- don't block
            // this thread waiting for the user's response! After the user
            // sees the explanation, try again to request the permission.
            showRationaly(Manifest.permission.WRITE_EXTERNAL_STORAGE);
        } else {/*  w w w.  j  ava  2s. co  m*/
            // No explanation needed, we can request the permission.
            ActivityCompat.requestPermissions(this,
                    new String[] { Manifest.permission.WRITE_EXTERNAL_STORAGE,
                            Manifest.permission.READ_EXTERNAL_STORAGE },
                    ApplicationScreen.STORAGE_PERMISSION_CODE);
        }
    } else
        storagePermissionGranted = true;
}

From source file:cl.gisred.android.InspActivity.java

private void verifPermisos() {
    if (ContextCompat.checkSelfPermission(InspActivity.this,
            Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED) {

        // Should we show an explanation?
        if (ActivityCompat.shouldShowRequestPermissionRationale(InspActivity.this,
                Manifest.permission.ACCESS_FINE_LOCATION)) {

        } else {//from  w  w  w  . j  av  a 2 s .  c  om
            // No explanation needed, we can request the permission.

            ActivityCompat.requestPermissions(InspActivity.this,
                    new String[] { Manifest.permission.ACCESS_FINE_LOCATION },
                    Util.REQUEST_ACCESS_FINE_LOCATION);
        }
    } else {
        initGeoposition();
    }

    if (ContextCompat.checkSelfPermission(InspActivity.this,
            Manifest.permission.READ_EXTERNAL_STORAGE) != PackageManager.PERMISSION_GRANTED) {
        if (ActivityCompat.shouldShowRequestPermissionRationale(InspActivity.this,
                Manifest.permission.READ_EXTERNAL_STORAGE)) {

        } else {
            // No explanation needed, we can request the permission.

            ActivityCompat.requestPermissions(InspActivity.this,
                    new String[] { Manifest.permission.READ_EXTERNAL_STORAGE },
                    Util.REQUEST_READ_EXTERNAL_STORAGE);
        }
    }

    if (ContextCompat.checkSelfPermission(InspActivity.this,
            Manifest.permission.WRITE_EXTERNAL_STORAGE) != PackageManager.PERMISSION_GRANTED) {
        if (ActivityCompat.shouldShowRequestPermissionRationale(InspActivity.this,
                Manifest.permission.WRITE_EXTERNAL_STORAGE)) {

        } else {
            // No explanation needed, we can request the permission.

            ActivityCompat.requestPermissions(InspActivity.this,
                    new String[] { Manifest.permission.WRITE_EXTERNAL_STORAGE },
                    Util.REQUEST_WRITE_EXTERNAL_STORAGE);
        }
    }

}

From source file:com.cs528.style.style.weather.WeatherActivity.java

void getCityByLocation() {
    if (ContextCompat.checkSelfPermission(this,
            Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED) {
        if (ActivityCompat.shouldShowRequestPermissionRationale(this, Manifest.permission.READ_CONTACTS)) {
            // Explanation not needed, since user requests this himself

        } else {//from   w  w w.  j  a va2  s  . c  om
            ActivityCompat.requestPermissions(this, new String[] { Manifest.permission.ACCESS_FINE_LOCATION },
                    MY_PERMISSIONS_ACCESS_FINE_LOCATION);
        }

    } else {
        progressDialog.setMessage(getString(R.string.getting_location));
        progressDialog.setCanceledOnTouchOutside(false);
        progressDialog.show();
        LocationManager locationManager = (LocationManager) getSystemService(LOCATION_SERVICE);
        locationManager.requestLocationUpdates(LocationManager.NETWORK_PROVIDER, 0, 0, this);
    }
}

From source file:com.ichi2.anki.DeckPicker.java

public void onRequestPermissionsResult(int requestCode, String[] permissions, int[] grantResults) {
    if (requestCode == REQUEST_STORAGE_PERMISSION && permissions.length == 1) {
        if (grantResults[0] == PackageManager.PERMISSION_GRANTED) {
            showStartupScreensAndDialogs(AnkiDroidApp.getSharedPrefs(this), 0);
        } else {/*from  w w w  .ja  v a  2s .c o m*/
            showSimpleSnackbar(R.string.directory_inaccessible, false);
        }
    }
}

From source file:com.almalence.opencam.ApplicationScreen.java

@Override
public void onRequestPermissionsResult(int requestCode, String permissions[], int[] grantResults) {
    boolean permissionResult = false;

    // If request is cancelled, the result arrays are empty.
    if (grantResults.length > 0) {
        for (int result : grantResults) {
            // If any of requested permission is granted, we consider that as success.
            if (result == PackageManager.PERMISSION_GRANTED) {
                permissionResult = true;
            }//from  ww  w  . j a va2  s . co  m
        }
    }

    switch (requestCode) {
    case ApplicationScreen.CAMERA_PERMISSION_CODE: {
        cameraPermissionGranted = permissionResult;
        return;
    }
    case ApplicationScreen.LOCATION_PERMISSION_CODE: {
        locationPermissionGranted = permissionResult;
        return;
    }
    case ApplicationScreen.MICROPHONE_PERMISSION_CODE: {
        microphonePermissionGranted = permissionResult;
        //restart camera if granted. on Nexus 5 camera hangs without restart.
        if (microphonePermissionGranted)
            relaunchCamera();

        return;
    }
    case ApplicationScreen.STORAGE_PERMISSION_CODE: {
        if (grantResults.length > 0) {
            permissionResult = true;
            for (int result : grantResults) {
                // For storage permissions we should check, that all permissions are granted.
                // If one of storage permissions isn't granted, then we don't have enough access to device's memory.
                // It means, that we can't read or write files. So we treat it as we don't have access to storage at all.
                if (result != PackageManager.PERMISSION_GRANTED) {
                    permissionResult = false;
                }
            }
        }

        storagePermissionGranted = permissionResult;
        return;
    }
    }
}

From source file:com.dvn.vindecoder.ui.user.GetAllVehicalDetails.java

public boolean checkCondition() {

    if (chck_geo_boolean) {
        //displayPromptForEnablingGPS(GetAllVehicalDetails.this);
        return true;
    } else {//w  ww  .  ja v  a 2  s.c  o  m

        try {
            if (android.os.Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
                int hasReadContactPermission = GetAllVehicalDetails.this
                        .checkSelfPermission(Manifest.permission.ACCESS_FINE_LOCATION);
                if (hasReadContactPermission != PackageManager.PERMISSION_GRANTED) {
                    requestPermissions(new String[] { Manifest.permission.ACCESS_FINE_LOCATION }, 101);
                    chck_geo_boolean = true;
                } else {
                    chck_geo_boolean = true;
                }
            } else {
                chck_geo_boolean = true;
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
    return checkCondition();
}