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:arc.noaa.weather.activities.MainActivity.java
@Override public void onRequestPermissionsResult(int requestCode, String permissions[], int[] grantResults) { switch (requestCode) { case MY_PERMISSIONS_ACCESS_FINE_LOCATION: { // If request is cancelled, the result arrays are empty. if (grantResults.length > 0 && grantResults[0] == PackageManager.PERMISSION_GRANTED) { getCityByLocation();//from w ww . ja v a2s . com } return; } } }
From source file:com.dvn.vindecoder.ui.user.GetAllVehicalDetails.java
public boolean checkCondition1() { if (chck_geo_boolean) { buildGoogleApiClient();//w ww .j a v a 2 s . c o m return true; } else { try { if (android.os.Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) { int hasReadContactPermission = GetAllVehicalDetails.this .checkSelfPermission(Manifest.permission.ACCESS_COARSE_LOCATION); if (hasReadContactPermission != PackageManager.PERMISSION_GRANTED) { requestPermissions(new String[] { Manifest.permission.ACCESS_COARSE_LOCATION }, 102); chck_geo_boolean1 = true; } else { chck_geo_boolean1 = true; } } else { chck_geo_boolean1 = true; } } catch (Exception e) { e.printStackTrace(); } } return checkCondition1(); }
From source file:cl.gisred.android.InspActivity.java
private void verifAccesoExterno(String sFoto) { if (ContextCompat.checkSelfPermission(InspActivity.this, Manifest.permission.WRITE_EXTERNAL_STORAGE) != PackageManager.PERMISSION_GRANTED) { // Should we show an explanation? if (ActivityCompat.shouldShowRequestPermissionRationale(InspActivity.this, Manifest.permission.WRITE_EXTERNAL_STORAGE)) { } else {//from ww w. ja va2s . c om // No explanation needed, we can request the permission. ActivityCompat.requestPermissions(InspActivity.this, new String[] { Manifest.permission.WRITE_EXTERNAL_STORAGE }, Util.REQUEST_WRITE_EXTERNAL_STORAGE); } } if (ContextCompat.checkSelfPermission(InspActivity.this, Manifest.permission.READ_EXTERNAL_STORAGE) != PackageManager.PERMISSION_GRANTED) { // Should we show an explanation? 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); } } else { imageGallery(sFoto); } }
From source file:cl.gisred.android.InspActivity.java
private void verifCamara(String sFoto) { if (ContextCompat.checkSelfPermission(InspActivity.this, Manifest.permission.CAMERA) != PackageManager.PERMISSION_GRANTED) { // Should we show an explanation? if (ActivityCompat.shouldShowRequestPermissionRationale(InspActivity.this, Manifest.permission.CAMERA)) { } else {//from w ww . j a v a2 s . c o m // No explanation needed, we can request the permission. ActivityCompat.requestPermissions(InspActivity.this, new String[] { Manifest.permission.CAMERA }, Util.REQUEST_CAMERA); } } else { tomarFoto(sFoto); } }
From source file:cm.aptoide.com.facebook.android.Facebook.java
/** * Generate a UI dialog for the request action in the given Android context * with the provided parameters./*from w w w.j a v a2 s. c o m*/ * * Note that this method is asynchronous and the callback will be invoked in * the original calling thread (not in a background thread). * * @param context * The Android context in which we will generate this dialog. * @param action * String representation of the desired method: e.g. "feed" ... * @param parameters * String key-value pairs to be passed as URL parameters. * @param listener * Callback interface to notify the application when the dialog * has completed. */ public void dialog(Context context, String action, Bundle parameters, final DialogListener listener) { String endpoint = DIALOG_BASE_URL + action; parameters.putString("display", "touch"); parameters.putString("redirect_uri", REDIRECT_URI); if (action.equals(LOGIN)) { parameters.putString("type", "user_agent"); parameters.putString("client_id", mAppId); } else { parameters.putString("app_id", mAppId); } if (isSessionValid()) { parameters.putString(TOKEN, getAccessToken()); } String url = endpoint + "?" + Util.encodeUrl(parameters); if (context .checkCallingOrSelfPermission(Manifest.permission.INTERNET) != PackageManager.PERMISSION_GRANTED) { Util.showAlert(context, "Error", "Application requires permission to access the Internet"); } else { new FbDialog(context, url, listener).show(); } }
From source file:com.dvn.vindecoder.ui.user.GetAllVehicalDetails.java
/** * Runs when a GoogleApiClient object successfully connects. *///from ww w . jav a 2 s.c o m @Override public void onConnected(Bundle connectionHint) { // Provides a simple way of getting a device's location and is well suited for // applications that do not require a fine-grained location and that do not need location // updates. Gets the best and most recent location currently available, which may be null // in rare cases when a location is not available. if (ActivityCompat.checkSelfPermission(GetAllVehicalDetails.this, Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED && ActivityCompat.checkSelfPermission(GetAllVehicalDetails.this, Manifest.permission.ACCESS_COARSE_LOCATION) != PackageManager.PERMISSION_GRANTED) { // TODO: Consider calling // ActivityCompat#requestPermissions // 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 ActivityCompat#requestPermissions for more details. return; } mLastLocation = LocationServices.FusedLocationApi.getLastLocation(mGoogleApiClient); if (mLastLocation != null) { /* mLatitudeText.setText(String.format("%s: %f", mLatitudeLabel, mLastLocation.getLatitude()));*/ latitude = mLastLocation.getLatitude(); /*mLongitudeText.setText(String.format("%s: %f", mLongitudeLabel, mLastLocation.getLongitude()));*/ longitute = mLastLocation.getLongitude(); Log.e("LAT LONG VALUE", "" + latitude + " , " + longitute); } else { Toast.makeText(GetAllVehicalDetails.this, "No location detected please start location setting", Toast.LENGTH_LONG).show(); // displayPromptForEnablingGPS(GetAllVehicalDetails.this); } }
From source file:com.adamas.client.android.MainActivity.java
private void checkCameraPermission() { if (ContextCompat.checkSelfPermission(this, Manifest.permission.CAMERA) != PackageManager.PERMISSION_GRANTED) { // Should we show an explanation? if (ActivityCompat.shouldShowRequestPermissionRationale(this, Manifest.permission.CAMERA)) { // 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. } else {// ww w . ja v a2 s.c o m // No explanation needed, we can request the permission. ActivityCompat.requestPermissions(this, new String[] { Manifest.permission.CAMERA }, MY_PERMISSIONS_REQUEST_CAMERA); // MY_PERMISSIONS_REQUEST_READ_CONTACTS is an // app-defined int constant. The callback method gets the // result of the request. } } else { onRequestPermissionsResult(MY_PERMISSIONS_REQUEST_CAMERA, new String[0], new int[] { PackageManager.PERMISSION_GRANTED }); } }
From source file:com.jamsuni.jamsunicodescan.MainActivity.java
public void checkPermissionsForAboveMarshmallow() { List<String> listReqPermission = new ArrayList<>(); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) { if (ContextCompat.checkSelfPermission(this, android.Manifest.permission.READ_EXTERNAL_STORAGE) != PackageManager.PERMISSION_GRANTED) { listReqPermission.add(android.Manifest.permission.READ_EXTERNAL_STORAGE); }/*from w w w . ja va2 s .com*/ if (ContextCompat.checkSelfPermission(this, android.Manifest.permission.WRITE_EXTERNAL_STORAGE) != PackageManager.PERMISSION_GRANTED) { listReqPermission.add(android.Manifest.permission.WRITE_EXTERNAL_STORAGE); } if (listReqPermission.size() > 0) { ActivityCompat.requestPermissions(this, listReqPermission.toArray(new String[listReqPermission.size()]), MY_PERMISSIONS_REQUEST); } else { // ? return; } } else { // ? return; } }
From source file:app.clirnet.com.clirnetapp.activity.LoginActivity.java
@TargetApi(Build.VERSION_CODES.JELLY_BEAN) public void onRequestPermissionsResult(int requestCode, @NonNull String permissions[], @NonNull int[] grantResults) { // Log.d(TAG, "Permission callback called-------"); switch (requestCode) { case REQUEST_ID_MULTIPLE_PERMISSIONS: { Map<String, Integer> perms = new HashMap<>(); // Initialize the map with both permissions perms.put(Manifest.permission.READ_EXTERNAL_STORAGE, PackageManager.PERMISSION_GRANTED); perms.put(Manifest.permission.WRITE_EXTERNAL_STORAGE, PackageManager.PERMISSION_GRANTED); perms.put(Manifest.permission.CAMERA, PackageManager.PERMISSION_GRANTED); perms.put(Manifest.permission.READ_PHONE_STATE, PackageManager.PERMISSION_GRANTED); perms.put(Manifest.permission.ACCESS_NETWORK_STATE, PackageManager.PERMISSION_GRANTED); perms.put(Manifest.permission.INTERNET, PackageManager.PERMISSION_GRANTED); perms.put(Manifest.permission.READ_LOGS, PackageManager.PERMISSION_GRANTED); // Fill with actual results from user if (grantResults.length > 0) { for (int i = 0; i < permissions.length; i++) perms.put(permissions[i], grantResults[i]); // Check for both permissions if (perms.get(Manifest.permission.READ_EXTERNAL_STORAGE) == PackageManager.PERMISSION_GRANTED && perms.get( Manifest.permission.WRITE_EXTERNAL_STORAGE) == PackageManager.PERMISSION_GRANTED && perms.get(Manifest.permission.CAMERA) == PackageManager.PERMISSION_GRANTED && perms.get(Manifest.permission.READ_PHONE_STATE) == PackageManager.PERMISSION_GRANTED && perms.get(Manifest.permission.ACCESS_NETWORK_STATE) == PackageManager.PERMISSION_GRANTED && perms.get(Manifest.permission.INTERNET) == PackageManager.PERMISSION_GRANTED && perms.get(Manifest.permission.READ_LOGS) == PackageManager.PERMISSION_GRANTED) { // Log.d(TAG, "sms & location services permission granted"); // process the normal flow //else any one or both the permissions are not granted } else { // Log.d(TAG, "Some permissions are not granted ask again "); //permission is denied (this is the first time, when "never ask again" is not checked) so ask again explaining the usage of permission // // shouldShowRequestPermissionRationale will return true //show the dialog or snackbar saying its necessary and try again otherwise proceed with setup. if (ActivityCompat.shouldShowRequestPermissionRationale(this, Manifest.permission.READ_EXTERNAL_STORAGE) || ActivityCompat.shouldShowRequestPermissionRationale(this, Manifest.permission.WRITE_EXTERNAL_STORAGE) || ActivityCompat.shouldShowRequestPermissionRationale(this, Manifest.permission.CAMERA) || ActivityCompat.shouldShowRequestPermissionRationale(this, Manifest.permission.READ_PHONE_STATE) || ActivityCompat.shouldShowRequestPermissionRationale(this, Manifest.permission.ACCESS_NETWORK_STATE) || ActivityCompat.shouldShowRequestPermissionRationale(this, Manifest.permission.INTERNET) || ActivityCompat.shouldShowRequestPermissionRationale(this, Manifest.permission.READ_LOGS)) { showDialogOK("Camera and Location Services Permission required for this app", new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { switch (which) { case DialogInterface.BUTTON_POSITIVE: checkAndRequestPermissions(); break; case DialogInterface.BUTTON_NEGATIVE: // proceed with logic by disabling the related features or quit the app. break; }//from w ww .ja v a 2s . c om } }); } //permission is denied (and never ask again is checked) //shouldShowRequestPermissionRationale will return false else { /* Toast.makeText(this, "Go to settings and enable permissions", Toast.LENGTH_LONG) .show();*/ // //proceed with logic by disabling the related features or quit the app. } } } } } }
From source file:com.jamsuni.jamsunicodescan.MainActivity.java
@Override public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions, @NonNull int[] grantResults) { super.onRequestPermissionsResult(requestCode, permissions, grantResults); switch (requestCode) { case MY_PERMISSIONS_REQUEST: { // ? ?? //from w ww. ja v a 2 s . co m if (grantResults[0] == PackageManager.PERMISSION_GRANTED) { // ? return; } // ? ? ? else { Toast.makeText(getApplicationContext(), "", Toast.LENGTH_LONG).show(); finish(); } } } }