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:me.kartikarora.transfersh.activities.DownloadActivity.java
private void checkForDownload(String name, String type, String url, View view) { if (ActivityCompat.checkSelfPermission(getApplicationContext(), android.Manifest.permission.WRITE_EXTERNAL_STORAGE) == PackageManager.PERMISSION_GRANTED) beginDownload(name, type, url);// w w w .j a v a2 s.c o m else { if (ActivityCompat.shouldShowRequestPermissionRationale(DownloadActivity.this, Manifest.permission.WRITE_EXTERNAL_STORAGE)) showRationale(view); else { showPermissionDialog(); checkForDownload(name, type, url, view); } } }
From source file:com.andrew67.ddrfinder.activity.MapViewer.java
@Override public void onMapReady(GoogleMap googleMap) { mMap = googleMap;//from w w w . j a v a 2 s. co m // Check for location permission, and request if disabled // This permission allows the user to locate themselves on the map if (ContextCompat.checkSelfPermission(this, android.Manifest.permission.ACCESS_FINE_LOCATION) == PackageManager.PERMISSION_GRANTED) { mMap.setMyLocationEnabled(true); if (onCreateSavedInstanceState == null) { zoomToCurrentLocation(); } } else { ActivityCompat.requestPermissions(this, new String[] { android.Manifest.permission.ACCESS_FINE_LOCATION }, PERMISSIONS_REQUEST_LOCATION); } // Restore previously loaded areas locations, and sources if available // (and re-create the location markers) if (onCreateSavedInstanceState != null && onCreateSavedInstanceState.containsKey("loadedAreas") && onCreateSavedInstanceState.containsKey("loadedLocations") && onCreateSavedInstanceState.containsKey("loadedSources")) { final ArrayList<LatLngBounds> savedLoadedAreas = onCreateSavedInstanceState .getParcelableArrayList("loadedAreas"); if (savedLoadedAreas != null) loadedAreas.addAll(savedLoadedAreas); final ArrayList<ArcadeLocation> savedLoadedLocations = onCreateSavedInstanceState .getParcelableArrayList("loadedLocations"); final ArrayList<DataSource> savedLoadedSources = onCreateSavedInstanceState .getParcelableArrayList("loadedSources"); if (savedLoadedSources != null) { for (DataSource src : savedLoadedSources) { loadedSources.put(src.getShortName(), src); } } MapLoader.fillMap(mMap, currentMarkers, savedLoadedLocations); } mMap.setOnCameraChangeListener(new GoogleMap.OnCameraChangeListener() { @Override public void onCameraChange(CameraPosition position) { if (isAutoloadEnabled()) { updateMap(false); } } }); mMap.setOnMarkerClickListener(actionModeEnabler); mMap.setOnMapClickListener(actionModeDisabler); mMap.setOnInfoWindowClickListener(moreInfoListener); }
From source file:at.ac.tuwien.caa.docscan.camera.LocationHandler.java
public Location getLocation() { if (mLocation != null) return mLocation; else {//w ww.java2 s .c om // If no location has been found yet, use the last known location as a fallback: if (ActivityCompat.checkSelfPermission(mContext, Manifest.permission.ACCESS_FINE_LOCATION) == PackageManager.PERMISSION_GRANTED) { Location l1 = mLocationManager.getLastKnownLocation(LocationManager.GPS_PROVIDER); Location l2 = mLocationManager.getLastKnownLocation(LocationManager.NETWORK_PROVIDER); if (l1 != null && l2 != null) { if (l1.getAccuracy() > l2.getAccuracy()) return l1; else return l2; } else { if (l1 != null) return l1; else return l2; } } } // If the user has given no permission to access location return nothing: return null; }
From source file:com.geozen.demo.foursquare.jiramot.Foursquare.java
public void dialog(Context context, String action, Bundle parameters, final DialogListener listener) { String endpoint = ""; parameters.putString("client_id", mClientId); parameters.putString("display", "touch"); if (action.equals(LOGIN)) { endpoint = AUTHENTICATE_URL; parameters.putString("client_secret", mClientSecret); parameters.putString("response_type", "token"); parameters.putString("redirect_uri", REDIRECT_URI); }/* w w w.j av a 2 s. com*/ 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 { mDialog = new FoursquareDialog(context, url, listener); mDialog.show(); } }
From source file:com.ae.apps.tripmeter.fragments.expenses.TripsListFragment.java
private void checkPermissions() { if (ContextCompat.checkSelfPermission(getActivity(), Manifest.permission.READ_CONTACTS) != PackageManager.PERMISSION_GRANTED) { // API 23 (Marshmallow) and above require certain permissions to be granted explicitly by the user // Since we need this permission to continue, lets request the same if (ActivityCompat.shouldShowRequestPermissionRationale(getActivity(), Manifest.permission.READ_CONTACTS)) { // Prompt the user to grant permission AlertDialog.Builder builder = new AlertDialog.Builder(getActivity()); builder.setPositiveButton(android.R.string.yes, new DialogInterface.OnClickListener() { @Override/*from ww w . jav a 2 s . c o m*/ public void onClick(DialogInterface dialog, int which) { requestPermissions(new String[] { Manifest.permission.READ_CONTACTS }, PERMISSIONS_REQUEST_READ_CONTACTS); dialog.dismiss(); } }).setNegativeButton(android.R.string.no, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { dialog.dismiss(); } }).setMessage(R.string.str_permission_contacts_reason).setTitle(R.string.str_permission_title); builder.create().show(); } else { // Request permission without prompting with a Rationale requestPermissions(new String[] { Manifest.permission.READ_CONTACTS }, PERMISSIONS_REQUEST_READ_CONTACTS); } } else { // Permission is granted, so load the Expenses View createExpenseView(); } }
From source file:com.wiret.arbrowser.AbstractArchitectCamActivity.java
/** Called when the activity is first created. */ @SuppressLint("NewApi") @Override//from w w w . ja va 2 s . c o m public void onCreate(final Bundle savedInstanceState) { super.onCreate(savedInstanceState); this.requestWindowFeature(Window.FEATURE_NO_TITLE); this.getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN); /* pressing volume up/down should cause music volume changes */ this.setVolumeControlStream(AudioManager.STREAM_MUSIC); this.setTitle(this.getActivityTitle()); /* * this enables remote debugging of a WebView on Android 4.4+ when debugging = true in AndroidManifest.xml * If you get a compile time error here, ensure to have SDK 19+ used in your ADT/Eclipse. * You may even delete this block in case you don't need remote debugging or don't have an Android 4.4+ device in place. * Details: https://developers.google.com/chrome-developer-tools/docs/remote-debugging */ if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) { if (0 != (getApplicationInfo().flags &= ApplicationInfo.FLAG_DEBUGGABLE)) { WebView.setWebContentsDebuggingEnabled(true); } } kmlFile = getIntent().getData(); if (ContextCompat.checkSelfPermission(this, Manifest.permission.READ_EXTERNAL_STORAGE) != PackageManager.PERMISSION_GRANTED) { ActivityCompat.requestPermissions(this, new String[] { android.Manifest.permission.READ_EXTERNAL_STORAGE, android.Manifest.permission.CAMERA, android.Manifest.permission.ACCESS_FINE_LOCATION }, 101); } else { try { this.setContentView(this.getContentViewId()); initArView(); } catch (Exception rex) { this.architectView = null; AbstractArchitectCamActivity.this.runOnUiThread(new Runnable() { @Override public void run() { Toast.makeText(AbstractArchitectCamActivity.this, "AR not supported by this device.", Toast.LENGTH_LONG).show(); } }); Log.e(this.getClass().getName(), "Exception in ArchitectView.onCreate()", rex); finish(); } } }
From source file:ca.ualberta.cs.drivr.GPSTracker.java
/** * End the updating through the GPS./*w ww .ja va2 s. c o m*/ */ public void stopUsingGPS() { if (locationManger != null) { if (ActivityCompat.checkSelfPermission(mContext, Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED && ActivityCompat.checkSelfPermission(mContext, Manifest.permission.ACCESS_COARSE_LOCATION) != PackageManager.PERMISSION_GRANTED) { locationManger.removeUpdates(GPSTracker.this); } } }
From source file:cc.metapro.openct.allclasses.ExcelDialog.java
@Override public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions, @NonNull int[] grantResults) { super.onRequestPermissionsResult(requestCode, permissions, grantResults); if (requestCode == REQUEST_EXTERNAL_FILE_WRITE) { if (grantResults.length > 0 && grantResults[0] == PackageManager.PERMISSION_GRANTED) { showFilerChooser();//www .ja v a 2 s . c om } else { dismiss(); Toast.makeText(getActivity(), R.string.no_write_permission, Toast.LENGTH_LONG).show(); } } }
From source file:com.platform.middlewares.plugins.CameraPlugin.java
@Override public boolean handle(String target, final Request baseRequest, final HttpServletRequest request, final HttpServletResponse response) { // GET /_camera/take_picture ///* ww w.j av a 2 s .c o m*/ // Optionally pass ?overlay=<id> (see overlay ids below) to show an overlay // in picture taking mode // // Status codes: // - 200: Successful image capture // - 204: User canceled image picker // - 404: Camera is not available on this device // - 423: Multiple concurrent take_picture requests. Only one take_picture request may be in flight at once. // if (target.startsWith("/_camera/take_picture")) { Log.i(TAG, "handling: " + target + " " + baseRequest.getMethod()); final MainActivity app = MainActivity.app; if (app == null) { Log.e(TAG, "handle: context is null: " + target + " " + baseRequest.getMethod()); return BRHTTPHelper.handleError(500, "context is null", baseRequest, response); } if (globalBaseRequest != null) { Log.e(TAG, "handle: already taking a picture: " + target + " " + baseRequest.getMethod()); return BRHTTPHelper.handleError(423, null, baseRequest, response); } PackageManager pm = app.getPackageManager(); if (!pm.hasSystemFeature(PackageManager.FEATURE_CAMERA)) { Log.e(TAG, "handle: no camera available: "); return BRHTTPHelper.handleError(402, null, baseRequest, response); } if (ContextCompat.checkSelfPermission(app, Manifest.permission.CAMERA) != PackageManager.PERMISSION_GRANTED) { // Should we show an explanation? if (ActivityCompat.shouldShowRequestPermissionRationale(app, Manifest.permission.CAMERA)) { Log.e(TAG, "handle: no camera access, showing instructions"); ((BreadWalletApp) app.getApplication()).showCustomToast(app, app.getString(R.string.allow_camera_access), MainActivity.screenParametersPoint.y / 2, Toast.LENGTH_LONG, 0); } else { // No explanation needed, we can request the permission. ActivityCompat.requestPermissions(app, new String[] { Manifest.permission.CAMERA }, BRConstants.CAMERA_REQUEST_GLIDERA_ID); } } else { Intent takePictureIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE); if (takePictureIntent.resolveActivity(app.getPackageManager()) != null) { app.startActivityForResult(takePictureIntent, REQUEST_IMAGE_CAPTURE); } continuation = ContinuationSupport.getContinuation(request); continuation.suspend(response); globalBaseRequest = baseRequest; } return true; } else if (target.startsWith("/_camera/picture/")) { Log.i(TAG, "handling: " + target + " " + baseRequest.getMethod()); final MainActivity app = MainActivity.app; if (app == null) { Log.e(TAG, "handle: context is null: " + target + " " + baseRequest.getMethod()); return BRHTTPHelper.handleError(500, "context is null", baseRequest, response); } String id = target.replace("/_camera/picture/", ""); byte[] pictureBytes = readPictureForId(app, id); if (pictureBytes == null) { Log.e(TAG, "handle: WARNING pictureBytes is null: " + target + " " + baseRequest.getMethod()); return BRHTTPHelper.handleError(500, "pictureBytes is null", baseRequest, response); } byte[] imgBytes = pictureBytes; String b64opt = request.getParameter("base64"); String contentType = "image/jpeg"; if (b64opt != null && !b64opt.isEmpty()) { contentType = "text/plain"; String b64 = "data:image/jpeg;base64," + Base64.encodeToString(pictureBytes, Base64.NO_WRAP); try { imgBytes = b64.getBytes("UTF-8"); } catch (UnsupportedEncodingException e) { e.printStackTrace(); return BRHTTPHelper.handleError(500, null, baseRequest, response); } } return BRHTTPHelper.handleSuccess(200, null, baseRequest, response, contentType); } else return false; }