List of usage examples for android.content.pm PackageManager PERMISSION_GRANTED
int PERMISSION_GRANTED
To view the source code for android.content.pm PackageManager PERMISSION_GRANTED.
Click Source Link
From source file:ca.uqac.florentinth.speakerauthentication.MainActivity.java
private void checkExternalStoragePermissions() { if (ActivityCompat.checkSelfPermission(this, Manifest.permission.WRITE_EXTERNAL_STORAGE) != PackageManager.PERMISSION_GRANTED) { requestExternalStoragePermissions(); } else {/*from w w w .j a v a 2 s.co m*/ checkLocationPermissions(); } }
From source file:com.money.manager.ex.utils.MmxFileUtils.java
private boolean requestPermission(String permission, Activity activity, int requestId) { boolean requesting = false; int permissionResult = ContextCompat.checkSelfPermission(context, permission); if (permissionResult != PackageManager.PERMISSION_GRANTED) { requesting = true;/* w w w. j av a 2s . c o m*/ ActivityCompat.requestPermissions(activity, new String[] { permission }, requestId); } return requesting; /* // Should we show an explanation? if (ActivityCompat.shouldShowRequestPermissionRationale(activity, permission)) { // Show an expanation 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. // todo: show explanation? } else { // No explanation needed, we can request the permission. ActivityCompat.requestPermissions(activity, new String[]{ permission }, PERMISSION_REQUEST_EXTERNAL_STORAGE); // MY_PERMISSIONS_REQUEST_READ_CONTACTS is an // app-defined int constant. The callback method gets the // result of the request. } */ }
From source file:ch.ethz.inf.vs.a1.fabischn.ble.MainActivity.java
public void onRequestPermissionsResult(int requestCode, String permissions[], int[] grantResults) { switch (requestCode) { case 1: {// www.j ava2 s. c om // If request is cancelled, the result arrays are empty. if (grantResults.length > 0 && grantResults[0] == PackageManager.PERMISSION_GRANTED) { } 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:atlc.granadaaccessibilityranking.VoiceActivity.java
/** * Checks whether the user has granted permission to the microphone. If the permission has not been provided, * it is requested. The result of the request (whether the user finally grants the permission or not) * is processed in the onRequestPermissionsResult method. * * This is necessary from Android 6 (API level 23), in which users grant permissions to apps * while the app is running. In previous versions, the permissions were granted when installing the app * See: http://developer.android.com/intl/es/training/permissions/requesting.html *//* www . ja v a2s. c o m*/ public void checkASRPermission() { if (ContextCompat.checkSelfPermission(ctx, Manifest.permission.RECORD_AUDIO) != PackageManager.PERMISSION_GRANTED) { // If an explanation is required, show it if (ActivityCompat.shouldShowRequestPermissionRationale((Activity) ctx, Manifest.permission.RECORD_AUDIO)) showRecordPermissionExplanation(); // Request the permission. ActivityCompat.requestPermissions((Activity) ctx, new String[] { Manifest.permission.RECORD_AUDIO }, MY_PERMISSIONS_REQUEST_RECORD_AUDIO); //Callback in "onRequestPermissionResult" } }
From source file:at.bitfire.nophonespam.BlacklistActivity.java
@Override public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions, @NonNull int[] grantResults) { super.onRequestPermissionsResult(requestCode, permissions, grantResults); boolean ok = true; for (int result : grantResults) if (result != PackageManager.PERMISSION_GRANTED) ok = false;//from w w w . ja v a2 s . c om if (!ok) Snackbar.make(getWindow().getDecorView(), R.string.blacklist_permissions_required, Snackbar.LENGTH_INDEFINITE) .setAction(R.string.blacklist_request_permissions, new View.OnClickListener() { @Override public void onClick(View view) { ActivityCompat.requestPermissions(BlacklistActivity.this, new String[] { Manifest.permission.CALL_PHONE, Manifest.permission.READ_PHONE_STATE }, 0); } }).show(); }
From source file:com.ahmedabdelmeged.bluetoothmc.ui.BluetoothDevices.java
@Override public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions, @NonNull int[] grantResults) { switch (requestCode) { case REQUEST_ENABLE_FINE_LOCATION: // If request is cancelled, the result arrays are empty. if (grantResults.length > 0 && grantResults[0] == PackageManager.PERMISSION_GRANTED) { //permission granted! } else {//from w w w . j a v a2 s.c om Toast.makeText(this, "Access Location must be allowed for bluetooth Search", Toast.LENGTH_LONG) .show(); } } }
From source file:cn.yibulz.caviewtest.MainActivity.java
@Override public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions, @NonNull int[] grantResults) { switch (requestCode) { case REQUEST_CAMERA_PERMISSION: if (permissions.length != 1 || grantResults.length != 1) { throw new RuntimeException("Error on requesting camera permission."); }/*from w w w.j a v a 2s. c o m*/ if (grantResults[0] != PackageManager.PERMISSION_GRANTED) { Toast.makeText(this, R.string.camera_permission_not_granted, Toast.LENGTH_SHORT).show(); } // No need to start camera here; it is handled by onResume break; } }
From source file:ca.uqac.florentinth.speakerauthentication.MainActivity.java
private void checkLocationPermissions() { if (ActivityCompat.checkSelfPermission(this, Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED && ActivityCompat.checkSelfPermission(this, Manifest.permission.ACCESS_COARSE_LOCATION) != PackageManager.PERMISSION_GRANTED) { requestLocationPermissions();//from w w w .ja va2s . c o m } else { checkRecordAudioPermission(); } }
From source file:android.zetterstrom.com.snow.fragments.SnowFragment.java
private void checkPermission() { if (ContextCompat.checkSelfPermission(getActivity(), permission.ACCESS_COARSE_LOCATION) != PackageManager.PERMISSION_GRANTED) { requestPermissions(new String[] { permission.ACCESS_COARSE_LOCATION }, COARSE_PERMISSION_REQUEST_CODE); } else {/*from w w w .j av a 2s. c o m*/ findLocation(); } }
From source file:com.seamusdawkins.autocomplete.MainActivity.java
@Override public void onMapReady(GoogleMap map) { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) { if (checkSelfPermission( android.Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED && checkSelfPermission( android.Manifest.permission.ACCESS_COARSE_LOCATION) != PackageManager.PERMISSION_GRANTED) { // TODO: Consider calling // public void requestPermissions(@NonNull String[] permissions, int requestCode) // here to request the missing permissions, and then overriding // public void onRequestPermissionsResult(int requestCode, String[] permissions, // int[] grantResults) // to handle the case where the user grants the permission. See the documentation // for Activity#requestPermissions for more details. ActivityCompat.requestPermissions(this, new String[] { android.Manifest.permission.ACCESS_FINE_LOCATION }, REQUEST_PERMISSION); return; }/*from ww w . j a v a 2s. c o m*/ } else { //Do Your Stuff } map.setMyLocationEnabled(true); this.map = map; }