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:co.ldln.android.MapFragment.java

@Override
public void onRequestPermissionsResult(int requestCode, String permissions[], int[] grantResults) {
    switch (requestCode) {
    case 100: {/*from  w  ww  .j  av a  2 s.c o  m*/
        // If request is cancelled, the result arrays are empty.
        if (grantResults.length > 0 && grantResults[0] == PackageManager.PERMISSION_GRANTED) {

            // permission was granted, yay! Do the
            // storage-related task you need to do.
            loadOfflineMaps();
        } else {

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

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

From source file:com.iss.android.wearable.datalayer.MainActivity.java

private void CheckPermissions() {
    int permission = ActivityCompat.checkSelfPermission(this, Manifest.permission.WRITE_EXTERNAL_STORAGE);

    if (permission != PackageManager.PERMISSION_GRANTED) {
        // We don't have permission so prompt the user
        ActivityCompat.requestPermissions(this, PERMISSIONS_STORAGE, REQUEST_EXTERNAL_STORAGE);
    }/*from ww  w  .j a  v a2  s . c om*/

    permission = ActivityCompat.checkSelfPermission(this, Manifest.permission.ACCESS_FINE_LOCATION);

    if (permission != PackageManager.PERMISSION_GRANTED) {
        // We don't have permission so prompt the user
        ActivityCompat.requestPermissions(this, PERMISSIONS_LOCATION, REQUEST_FINE_LOCATION);
    }
}

From source file:com.newventuresoftware.waveformdemo.MainActivity.java

@Override
public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions,
        @NonNull int[] grantResults) {
    if (requestCode == REQUEST_RECORD_AUDIO && grantResults.length > 0
            && grantResults[0] == PackageManager.PERMISSION_GRANTED) {
        mRecordingThread.stopRecording();
    }/*from  www.  j a  v  a2s.c  o m*/
}

From source file:ai.api.lejossample.MainActivity.java

@Override
public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions,
        @NonNull int[] grantResults) {
    switch (requestCode) {
    case REQUEST_AUDIO_PERMISSIONS_ID: {
        // 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.

        } else {/*from www  .j a v  a  2  s. co  m*/

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

From source file:com.justinbull.ichnaeachecker.MainActivity.java

@Override
public void onRequestPermissionsResult(int requestCode, String[] permissions, int[] grantResults) {
    if (requestCode == Consts.REQUEST_COARSE_LOCATION && grantResults[0] == PackageManager.PERMISSION_GRANTED) {
        setCellInfo();//  ww  w. java2 s .c o m
    }
    super.onRequestPermissionsResult(requestCode, permissions, grantResults);
}

From source file:cn.motalks.mtdc.utils.EasyPermissionsEx.java

/**
 * Handle the result of a permission request, should be called from the calling Activity's
 * {@link ActivityCompat.OnRequestPermissionsResultCallback#onRequestPermissionsResult(int, String[], int[])}
 * method./*from  w  w  w .  j a v  a 2  s . c om*/
 * <p>
 * If any permissions were granted or denied, the {@code object} will receive the appropriate
 * callbacks through {@link PermissionCallbacks}
 *
 * @param requestCode  requestCode argument to permission result callback.
 * @param permissions  permissions argument to permission result callback.
 * @param grantResults grantResults argument to permission result callback.
 * @param receivers    an array of objects that implement {@link PermissionCallbacks}.
 */
public static void onRequestPermissionsResult(int requestCode, String[] permissions, int[] grantResults,
        Object... receivers) {

    // Make a collection of granted and denied permissions from the request.
    ArrayList<String> granted = new ArrayList<>();
    ArrayList<String> denied = new ArrayList<>();
    for (int i = 0; i < permissions.length; i++) {
        String perm = permissions[i];
        if (grantResults[i] == PackageManager.PERMISSION_GRANTED) {
            granted.add(perm);
        } else {
            denied.add(perm);
        }
    }

    // iterate through all receivers
    for (Object object : receivers) {
        // Report granted permissions, if any.
        if (!granted.isEmpty()) {
            if (object instanceof PermissionCallbacks) {
                ((PermissionCallbacks) object).onPermissionsGranted(requestCode, granted);
            }
        }

        // Report denied permissions, if any.
        if (!denied.isEmpty()) {
            if (object instanceof PermissionCallbacks) {
                ((PermissionCallbacks) object).onPermissionsDenied(requestCode, denied);
            }
        }
    }

}

From source file:com.adam.aslfms.SettingsActivity.java

private void permsCheck() {
    //PERMISSION CHECK
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
        try {//w  w w . j a  v a  2 s. com
            if (ContextCompat.checkSelfPermission(SettingsActivity.this,
                    Manifest.permission.READ_EXTERNAL_STORAGE) != PackageManager.PERMISSION_GRANTED) {
                ActivityCompat.requestPermissions(SettingsActivity.this,
                        new String[] { Manifest.permission.READ_EXTERNAL_STORAGE }, REQUEST_READ_STORAGE);
            }
        } catch (Exception e) {
            Log.e(TAG, "Version exception, READ_EXTERNAL_STORAGE. " + e);
        }
    }
}

From source file:com.airg.android.permission.PermissionsHandler.java

@Synchronized
public void onRequestPermissionsResult(final int requestCode, final String[] permissions,
        final int[] grantResults) {
    if (null == currentRequest || currentRequest.code != requestCode)
        return;//  w w  w  . j  a  va  2 s.co m

    if (permissions.length != grantResults.length) {
        currentRequest = null;
        throw new IllegalStateException("grantResults size does not match that of permissions");
    }

    for (int i = 0; i < permissions.length; i++) {
        if (grantResults[i] == PackageManager.PERMISSION_GRANTED)
            currentRequest.granted(permissions[i]);
        else
            currentRequest.denied(permissions[i]);
    }

    try {
        if (currentRequest.hasGrants()) {
            permissionsGranted(currentRequest.granted());
        }

        if (currentRequest.hasDenies()) {
            permissionsDeclined(currentRequest.denied());
        }
    } finally {
        currentRequest = null;
    }
}

From source file:ch.ethz.coss.nervousnet.vm.sensors.LocationSensor.java

@TargetApi(23)
public void startLocationCollection() {
    NNLog.d(LOG_TAG, "startLocationCollection ");

    if (locationManager == null)
        return;//from   ww w .ja v a 2s  . c  o m
    NNLog.d(LOG_TAG, "startLocationCollection2");
    // getting GPS status
    isGPSEnabled = locationManager.isProviderEnabled(LocationManager.GPS_PROVIDER);
    NNLog.d(LOG_TAG, "isGPSEnabled = " + isGPSEnabled);
    // getting network status
    isNetworkEnabled = locationManager.isProviderEnabled(LocationManager.NETWORK_PROVIDER);
    NNLog.d(LOG_TAG, "isNetworkEnabled = " + isNetworkEnabled);

    /////TODO:
    if (Build.VERSION.SDK_INT >= 23
            && ContextCompat.checkSelfPermission(mContext,
                    android.Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED
            && ContextCompat.checkSelfPermission(mContext,
                    android.Manifest.permission.ACCESS_COARSE_LOCATION) != PackageManager.PERMISSION_GRANTED) {
        setSensorState(NervousnetVMConstants.SENSOR_STATE_AVAILABLE_PERMISSION_DENIED);

    } else

    ////TODO:
    if (!isGPSEnabled && !isNetworkEnabled) {
        setSensorState(NervousnetVMConstants.SENSOR_STATE_AVAILABLE_PERMISSION_DENIED);
        NNLog.d(LOG_TAG, "Location settings disabled");
        // no network provider is enabled
        Toast.makeText(mContext, "Location settings disabled", Toast.LENGTH_LONG).show();
    } else {
        this.canGetLocation = true;
        // First get location from Network Provider
        if (isNetworkEnabled) {
            locationManager.requestLocationUpdates(LocationManager.NETWORK_PROVIDER, MIN_TIME_BW_UPDATES,
                    MIN_TIME_BW_UPDATES, this);
            NNLog.d(LOG_TAG, "Network");
            if (locationManager != null) {
                location = locationManager.getLastKnownLocation(LocationManager.NETWORK_PROVIDER);
                if (location != null) {
                    reading = new LocationReading(System.currentTimeMillis(),
                            new double[] { location.getLatitude(), location.getLongitude() });
                }
            }
        }
        // if GPS Enabled get lat/long using GPS Services
        if (isGPSEnabled) {
            if (location == null) {
                locationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, MIN_TIME_BW_UPDATES,
                        MIN_TIME_BW_UPDATES, this);

                NNLog.d(LOG_TAG, "GPS Enabled");

                if (locationManager != null) {
                    location = locationManager.getLastKnownLocation(LocationManager.GPS_PROVIDER);
                    if (location != null) {
                        reading = new LocationReading(System.currentTimeMillis(),
                                new double[] { location.getLatitude(), location.getLongitude() });
                    }
                }
            }
        }
        dataReady(reading);
    }

}

From source file:com.adkdevelopment.earthquakesurvival.ui.MapviewFragment.java

@Override
public void onRequestPermissionsResult(int requestCode, @NonNull String permissions[],
        @NonNull int[] grantResults) {
    switch (requestCode) {
    case LOCATION_PERMISSION: {
        // If request is cancelled, the result arrays are empty.
        if (grantResults.length > 0 && grantResults[0] == PackageManager.PERMISSION_GRANTED) {
            addMyLocation();// ww w  . ja v  a 2s.  co  m
        }
    }
    }
}