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:br.com.anteros.vendas.gui.ManutencaoTabelasActivity.java

@Override
public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions,
        @NonNull int[] grantResults) {
    super.onRequestPermissionsResult(requestCode, permissions, grantResults);
    if (requestCode == REQUEST_PERMISSION_EXPORT) {
        if (ActivityCompat.checkSelfPermission(ManutencaoTabelasActivity.this,
                Manifest.permission.WRITE_EXTERNAL_STORAGE) != PackageManager.PERMISSION_GRANTED
                || ActivityCompat.checkSelfPermission(ManutencaoTabelasActivity.this,
                        Manifest.permission.READ_EXTERNAL_STORAGE) != PackageManager.PERMISSION_GRANTED) {
            throw new BackupException(
                    "No foi possvel executar a exportao do banco de dados pois voc no possu permisso.");
        } else {/*from  w w w  .ja  v  a  2s  . c om*/
            executarExportacaoBancoDados();
        }
    } else if (requestCode == REQUEST_PERMISSION_IMPORT) {
        if (ActivityCompat.checkSelfPermission(ManutencaoTabelasActivity.this,
                Manifest.permission.WRITE_EXTERNAL_STORAGE) != PackageManager.PERMISSION_GRANTED
                || ActivityCompat.checkSelfPermission(ManutencaoTabelasActivity.this,
                        Manifest.permission.READ_EXTERNAL_STORAGE) != PackageManager.PERMISSION_GRANTED) {
            throw new BackupException(
                    "No foi possvel executar a importao do banco de dados pois voc no possu permisso.");
        } else {
            executarImportacaoBancoDados();
        }
    } else if (requestCode == REQUEST_PERMISSION_SHARE) {
        if (ActivityCompat.checkSelfPermission(ManutencaoTabelasActivity.this,
                Manifest.permission.WRITE_EXTERNAL_STORAGE) != PackageManager.PERMISSION_GRANTED
                || ActivityCompat.checkSelfPermission(ManutencaoTabelasActivity.this,
                        Manifest.permission.READ_EXTERNAL_STORAGE) != PackageManager.PERMISSION_GRANTED) {
            throw new BackupException(
                    "No foi possvel compartilhar o banco de dados pois voc no possu permisso.");
        } else {
            selecionarArquivoCompartilhar();
        }
    }
}

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

@Override
public void onConnected(Bundle bundle) {
    mLocationRequest = LocationRequest.create();
    mLocationRequest.setPriority(LocationRequest.PRIORITY_BALANCED_POWER_ACCURACY);
    mLocationRequest.setInterval(DateUtils.HOUR_IN_MILLIS);
    mLocationRequest.setFastestInterval(DateUtils.MINUTE_IN_MILLIS);

    String perm = Manifest.permission.ACCESS_FINE_LOCATION;

    if (ContextCompat.checkSelfPermission(this, perm) != PackageManager.PERMISSION_GRANTED) {
        loadPermissions(perm, REQUEST_FINE_LOCATION);
    } else {/*w ww . ja v a2s  .  c o  m*/
        LocationServices.FusedLocationApi.requestLocationUpdates(mGoogleApiClient, mLocationRequest, this);
        Location location = LocationServices.FusedLocationApi.getLastLocation(mGoogleApiClient);
        LocationUtils.setLocation(this, location);
    }
}

From source file:com.lge.friendsCamera.MainActivity.java

/**
 * Ask "write storage" permission to user
 *///from   w w  w .  ja  v a  2 s . co m
private void checkFileWritePermission() {
    int permissionCheck = ContextCompat.checkSelfPermission(mContext,
            Manifest.permission.WRITE_EXTERNAL_STORAGE);
    if (permissionCheck != PackageManager.PERMISSION_GRANTED) {
        ActivityCompat.requestPermissions((Activity) mContext,
                new String[] { Manifest.permission.WRITE_EXTERNAL_STORAGE },
                MY_PERMISSION_REQUEST_WRITE_EXTERNAL_STORAGE);
    }
}

From source file:br.com.brolam.cloudvision.ui.NoteVisionDetailsActivity.java

/**
 * Adicionar a imagem de background ao NotVision e tambm verificar a permisso a cmera
 * fotogrfica.//ww  w. j  a v  a 2  s. c om
 * @param noteVisionKey informar uma chave vlida
 * @param noteVision informar um NoteVision vlido.
 */
private void addNoteVisionBackground(String noteVisionKey, HashMap noteVision) {
    // Check for the camera permission before accessing the camera.  If the
    // permission is not granted yet, request permission.
    int rc = ActivityCompat.checkSelfPermission(this, Manifest.permission.CAMERA);
    if (rc == PackageManager.PERMISSION_GRANTED) {
        if (this.imagesHelper != null) {
            try {
                NoteVision.BackgroundOrigin backgroundOrigin = NoteVision.getBackground(noteVision);
                if (backgroundOrigin == NoteVision.BackgroundOrigin.LOCAL) {
                    Toast.makeText(this, R.string.note_vision_alert_background_image_in_processing,
                            Toast.LENGTH_LONG).show();
                } else {
                    this.imagesHelper.takeNoteVisionBackground(noteVisionKey);
                    this.appAnalyticsHelper.logNoteVisionAddBackground(TAG);
                }
            } catch (IOException e) {
                Log.e(TAG, e.getMessage());
                Toast.makeText(this, String.format(getString(R.string.main_activity_request_error),
                        ImagesHelper.REQUEST_IMAGE_CAPTURE), Toast.LENGTH_LONG).show();
            }
        }

    } else {
        ActivityHelper.requestCameraPermission(TAG, this, fab);
    }

}

From source file:au.com.dektech.dektalk.MainActivity.java

@Override
public void onRequestPermissionsResult(int requestCode, String permissions[], int[] grantResults) {
    super.onRequestPermissionsResult(requestCode, permissions, grantResults);
    switch (requestCode) {
    case PERMISSION_REQUEST_DANGEROUS: {
        // 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.
            resumeCall();//from  w  w  w. ja v  a2  s .  c  o m

        } else {
            // permission denied, boo! Disable the functionality that depends on this permission.
            Log.e(TAG, "Error: Permission(s) denied; aborting call");
        }
        return;
    }

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

From source file:com.andrew67.ddrfinder.activity.MapViewer.java

@Override
public void onRequestPermissionsResult(int requestCode, @NonNull String permissions[],
        @NonNull int[] grantResults) {
    switch (requestCode) {
    case PERMISSIONS_REQUEST_LOCATION:
        if (grantResults.length > 0 && grantResults[0] == PackageManager.PERMISSION_GRANTED) {
            try {
                mMap.setMyLocationEnabled(true);
            } catch (SecurityException e) {
                /* Satisfy linter; it should be granted */ }
            zoomToCurrentLocation();//from ww w . j  av  a 2 s. co m
        } else {
            showMessage(R.string.error_perm_loc);
        }
    }
}

From source file:it.unime.mobility4ckan.MainActivity.java

@Override
public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions,
        @NonNull int[] grantResults) {
    if (requestCode == REQUEST_PERMISSION_LOCATION) {
        if (grantResults[0] == PackageManager.PERMISSION_GRANTED) {
            checkPermissionControl();//w  ww. j  a  v  a2 s  . c o m
        } else {
            new AlertDialog.Builder(this).setMessage(getString(R.string.location_permission_denied_text))
                    .setPositiveButton("OK", null).create().show();
            super.onRequestPermissionsResult(requestCode, permissions, grantResults);
        }
    }
}

From source file:com.alibaba.weex.extend.module.GeolocationModule.java

private boolean checkPermission() {
    return ActivityCompat.checkSelfPermission(mWXSDKInstance.getContext(),
            Manifest.permission.ACCESS_FINE_LOCATION) == PackageManager.PERMISSION_GRANTED
            && ActivityCompat.checkSelfPermission(mWXSDKInstance.getContext(),
                    Manifest.permission.ACCESS_COARSE_LOCATION) == PackageManager.PERMISSION_GRANTED;
}

From source file:com.lge.friendsCamera.MainActivity.java

@Override
public void onRequestPermissionsResult(int requestCode, String[] permissions, int[] grantResults) {
    switch (requestCode) {
    case MY_PERMISSION_REQUEST_WRITE_EXTERNAL_STORAGE:
        if (grantResults.length > 0 && grantResults[0] == PackageManager.PERMISSION_GRANTED) {
            Log.d(TAG, "Permission for write external storage is granted");
        } else {//from w  ww  .  j av  a 2  s  .  c  om
            Log.d(TAG, "Permission for write external storage is denied");
        }
    }
}

From source file:at.ac.tuwien.caa.docscan.ui.CameraActivity.java

/**
 * Called after permission has been given or has been rejected. This is necessary on Android M
 * and younger Android systems./*from w  w w .  j  a va  2  s.  co  m*/
 *
 * @param requestCode Request code
 * @param permissions Permission
 * @param grantResults results
 */
@Override
public void onRequestPermissionsResult(int requestCode, String permissions[], int[] grantResults) {

    boolean isPermissionGiven = (grantResults.length == 1
            && grantResults[0] == PackageManager.PERMISSION_GRANTED);
    //        initCamera();
    switch (requestCode) {

    case PERMISSION_WRITE_EXTERNAL_STORAGE:
        if (isPermissionGiven && mPictureData != null)
            savePicture(mPictureData);
        break;
    case PERMISSION_ACCESS_FINE_LOCATION:
        if (isPermissionGiven)
            startLocationAccess();
        break;
    }
}