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:com.a3did.partner.recosample.MainActivity.java
@Override public void onRequestPermissionsResult(int requestCode, String[] permissions, int[] grantResults) { switch (requestCode) { case REQUEST_LOCATION: { if (grantResults[0] == PackageManager.PERMISSION_GRANTED) { Snackbar.make(mLayout, R.string.location_permission_granted, Snackbar.LENGTH_LONG).show(); } else {/*w w w. ja v a2s. c o m*/ Snackbar.make(mLayout, R.string.location_permission_not_granted, Snackbar.LENGTH_LONG).show(); } } default: break; } }
From source file:com.mobicage.rogerthat.registration.ContentBrandingRegistrationActivity.java
@Override public void onRequestPermissionsResult(int requestCode, String permissions[], int[] grantResults) { T.UI();//from w w w . j ava 2 s . c o m if (requestCode == MY_PERMISSIONS_REQUEST_CAMERA) { if (grantResults.length > 0 && grantResults[0] == PackageManager.PERMISSION_GRANTED) { startQRScan(); } } }
From source file:ch.epfl.sweng.team7.hikingapp.LoginActivity.java
@Override public void onRequestPermissionsResult(int requestCode, @NonNull String permissions[], @NonNull int[] grantResults) { Log.d(TAG, "onRequestPermissionsResult:" + requestCode); if (requestCode == RC_PERM_GET_ACCOUNTS) { if (grantResults.length > 0 && grantResults[0] == PackageManager.PERMISSION_GRANTED) { showSignedInUI();//from w w w.j av a 2 s. c o m } else { Log.d(TAG, "GET_ACCOUNTS Permission Denied."); } } }
From source file:com.github.michalbednarski.intentslab.Utils.java
@TargetApi(13) // Function handles all supported api levels public static InputStream dumpSystemService(Context context, String serviceName, final String[] arguments) throws Exception { // Check if we have permission to invoke dump from our process final boolean canDumpLocally = context.getPackageManager().checkPermission(android.Manifest.permission.DUMP, context.getPackageName()) == PackageManager.PERMISSION_GRANTED; // On versions without createPipe() just execute dumpsys if (android.os.Build.VERSION.SDK_INT < 9) { if (!canDumpLocally) { throw new Exception("Dumping is not supported on this system version"); }/*from w w w . j av a2s . c o m*/ String[] progArray = new String[arguments != null ? 2 + arguments.length : 2]; progArray[0] = "dumpsys"; progArray[1] = serviceName; if (arguments != null) { System.arraycopy(arguments, 0, progArray, 2, arguments.length); } return Runtime.getRuntime().exec(progArray).getInputStream(); } // Get service final Class<?> serviceManager = Class.forName("android.os.ServiceManager"); final IBinder service = (IBinder) serviceManager.getMethod("getService", String.class).invoke(null, serviceName); // Check permissions and get remote interface if needed IRemoteInterface remoteInterface = null; if (!canDumpLocally) { remoteInterface = RunAsManager.getRemoteInterfaceForSystemDebuggingCommands(); if (remoteInterface == null) { throw new SecurityException("Process has no permission to dump services"); } } // Create pipe, write(pipe[0]) -> read(pipe[1]) final ParcelFileDescriptor[] pipe = ParcelFileDescriptor.createPipe(); final ParcelFileDescriptor readablePipe = pipe[0]; final ParcelFileDescriptor writablePipe = pipe[1]; try { // Execute dump if (canDumpLocally) { if (android.os.Build.VERSION.SDK_INT >= 13) { service.dumpAsync(writablePipe.getFileDescriptor(), arguments); writablePipe.close(); } else { (new Thread() { @Override public void run() { try { service.dump(writablePipe.getFileDescriptor(), arguments); writablePipe.close(); } catch (Exception e) { // TODO: can we handle this? e.printStackTrace(); } } }).start(); } } else { remoteInterface.dumpServiceAsync(service, writablePipe, arguments); writablePipe.close(); } // If anything went wrong, close pipe and rethrow } catch (Throwable e) { readablePipe.close(); writablePipe.close(); throwUnchecked(e); throw new Error(); // Unreachable } // Return stream that will ensure closing fd return new FileInputStream(readablePipe.getFileDescriptor()) { @Override public void close() throws IOException { super.close(); readablePipe.close(); } }; }
From source file:com.mercandalli.android.apps.files.user.LoginRegisterActivity.java
/** * Action when the user clicked the Google + signing button **/// w w w . j a v a 2 s. c o m private void onGoogleSignInClicked() { if (ContextCompat.checkSelfPermission(this, GET_ACCOUNTS) == PackageManager.PERMISSION_GRANTED) { Intent signInIntent = Auth.GoogleSignInApi.getSignInIntent(mGoogleApiClient); startActivityForResult(signInIntent, RC_SIGN_IN); /* mShouldResolve = true; mGoogleApiClient.connect(); */ } else if (shouldRequestAccountPermissionRationale()) { requestAccountPermissionRationale(); } else { requestAccountPermissionInSettings(); } }
From source file:com.example.mapdemo.MyLocationDemoActivity.java
/** * Enables the My Location layer if the fine location permission has been granted. *//* w w w .java 2 s . c o m*/ private void enableMyLocation() { if (ContextCompat.checkSelfPermission(this, Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED) { // Permission to access the location is missing. PermissionUtils.requestPermission(this, LOCATION_PERMISSION_REQUEST_CODE, Manifest.permission.ACCESS_FINE_LOCATION, true); } else if (mMap != null) { // Access to the location has been granted to the app. mMap.setMyLocationEnabled(true); } }
From source file:com.elkriefy.android.apps.permissionmigrationguide.MainActivity.java
private void marshmallowonRequestPermissionsResult(int requestCode, @NonNull int[] grantResults) { switch (requestCode) { case MY_PERMISSIONS_REQUEST_ACCESS_FINE_LOCATION: { if (grantResults[0] == PackageManager.PERMISSION_GRANTED) { // permission was granted getLocation();/*from w ww . j a v a2 s . c o m*/ } else { // permission denied, boo! Disable the // functionality that depends on this permission. Toast.makeText(this, R.string.permission_denied, Toast.LENGTH_LONG).show(); } return; } } }
From source file:com.affectiva.affdexme.MainActivity.java
private void checkForCameraPermissions() { cameraPermissionsAvailable = ContextCompat.checkSelfPermission(getApplicationContext(), Manifest.permission.CAMERA) == PackageManager.PERMISSION_GRANTED; if (!cameraPermissionsAvailable) { // Should we show an explanation? if (ActivityCompat.shouldShowRequestPermissionRationale(this, Manifest.permission.CAMERA)) { // 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. showPermissionExplanationDialog(CAMERA_PERMISSIONS_REQUEST); } else {// ww w . j ava2s. c o m // No explanation needed, we can request the permission. requestCameraPermissions(); } } }
From source file:ca.appvelopers.mcgillmobile.ui.MapActivity.java
@Override public void onRequestPermissionsResult(int requestCode, @NonNull String permissions[], @NonNull int[] grantResults) { switch (requestCode) { case LOCATION_REQUEST: //Check if the permission has been granted if (grantResults.length > 0 && grantResults[0] == PackageManager.PERMISSION_GRANTED) { //Show the user on the map if that is the case if (map != null) { //noinspection MissingPermission map.setMyLocationEnabled(true); }// ww w .j a v a2s .co m } break; default: super.onRequestPermissionsResult(requestCode, permissions, grantResults); } }
From source file:alaindc.crowdroid.View.MainActivity.java
private void setLocationAndMap() { if (mMap == null) return;/* w ww . j av a 2s. c o m*/ if (ContextCompat.checkSelfPermission(this, android.Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED) { return; } int cameraZoom = 16; SharedPreferences sharedPref = getApplicationContext().getSharedPreferences(Constants.PREF_FILE, Context.MODE_PRIVATE); double latitude = Double.parseDouble(sharedPref.getString(Constants.PREF_LATITUDE, "-1")); double longitude = Double.parseDouble(sharedPref.getString(Constants.PREF_LONGITUDE, "-1")); if (latitude < 0 || longitude < 0) return; LatLng target = new LatLng(latitude, longitude); mMap.clear(); mMap.addMarker(new MarkerOptions().position(target).snippet("").title("")); for (int k : listGeofenceCircle.keySet()) { try { listCircles.get(k).remove(); } catch (Exception e) { Log.d("Main", "No circle"); } GeofenceCirceView circle = listGeofenceCircle.get(k); CircleOptions circleOptions = new CircleOptions().center(circle.latLng).strokeWidth(7) .fillColor(Color.argb(60, 255, 255, 255)).strokeColor(Color.argb(80, 255, 255, 255)) .radius(circle.radius); // In meters // Get back the mutable Circle Circle c = mMap.addCircle(circleOptions); listCircles.put(k, c); } CameraUpdate cameraUpdate = CameraUpdateFactory.newLatLngZoom(target, cameraZoom); mMap.animateCamera(cameraUpdate); mMap.setMyLocationEnabled(true); }