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.aero2.android.DefaultActivities.SmogMapActivity.java
@Override //This function is called once the dialog for asking permission is answered public void onRequestPermissionsResult(int requestCode, String[] permissions, int[] grantResults) { super.onRequestPermissionsResult(requestCode, permissions, grantResults); switch (requestCode) { case MY_PERMISSIONS_REQUEST: { // If request is cancelled, the result arrays are empty. if (grantResults.length > 0 && grantResults[0] == PackageManager.PERMISSION_GRANTED) { //Permission Granted YAY! if (ActivityCompat.checkSelfPermission(this, Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED && ActivityCompat.checkSelfPermission(this, Manifest.permission.ACCESS_COARSE_LOCATION) != PackageManager.PERMISSION_GRANTED) { // this scope is unreachable as the permission has been granted if we have entered the parent scope. return; }/* w w w . ja va2s .c o m*/ locationPermissionHasBeenGranted(); //once the permission to access fine location is granted restart the activity so that we can get the user's location refreshActivity(); } else { // permission denied, boo! Disable the // functionality that depends on this permission. } return; } } }
From source file:co.taqat.call.CallActivity.java
@Override public void onClick(View v) { int id = v.getId(); if (isVideoEnabled(LinphoneManager.getLc().getCurrentCall())) { //displayVideoCallControlsIfHidden(); }/*from w w w. j av a2 s .com*/ if (id == R.id.video) { int camera = getPackageManager().checkPermission(Manifest.permission.CAMERA, getPackageName()); Log.i("[Permission] Camera permission is " + (camera == PackageManager.PERMISSION_GRANTED ? "granted" : "denied")); if (camera == PackageManager.PERMISSION_GRANTED) { disableVideo(isVideoEnabled(LinphoneManager.getLc().getCurrentCall())); } else { checkAndRequestPermission(Manifest.permission.CAMERA, PERMISSIONS_ENABLED_CAMERA); } } else if (id == R.id.micro) { int recordAudio = getPackageManager().checkPermission(Manifest.permission.RECORD_AUDIO, getPackageName()); Log.i("[Permission] Record audio permission is " + (recordAudio == PackageManager.PERMISSION_GRANTED ? "granted" : "denied")); if (recordAudio == PackageManager.PERMISSION_GRANTED) { toggleMicro(); } else { checkAndRequestPermission(Manifest.permission.RECORD_AUDIO, PERMISSIONS_ENABLED_MIC); } } else if (id == R.id.speaker) { toggleSpeaker(); } else if (id == R.id.add_call) { goBackToDialer(); } else if (id == R.id.pause) { pauseOrResumeCall(LinphoneManager.getLc().getCurrentCall()); } else if (id == R.id.hang_up) { hangUp(); } else if (id == R.id.dialer) { hideOrDisplayNumpad(); } else if (id == R.id.chat) { goToChatList(); } else if (id == R.id.conference) { enterConference(); hideOrDisplayCallOptions(); } else if (id == R.id.switchCamera) { if (videoCallFragment != null) { videoCallFragment.switchCamera(); } } else if (id == R.id.transfer) { goBackToDialerAndDisplayTransferButton(); } else if (id == R.id.options) { hideOrDisplayCallOptions(); } else if (id == R.id.audio_route) { hideOrDisplayAudioRoutes(); } else if (id == R.id.route_bluetooth) { if (BluetoothManager.getInstance().routeAudioToBluetooth()) { isSpeakerEnabled = false; routeBluetooth.setImageResource(R.drawable.route_bluetooth_selected); routeSpeaker.setImageResource(R.drawable.route_speaker); routeEarpiece.setImageResource(R.drawable.route_earpiece); } hideOrDisplayAudioRoutes(); } else if (id == R.id.route_earpiece) { LinphoneManager.getInstance().routeAudioToReceiver(); isSpeakerEnabled = false; routeBluetooth.setImageResource(R.drawable.route_bluetooth); routeSpeaker.setImageResource(R.drawable.route_speaker); routeEarpiece.setImageResource(R.drawable.route_earpiece_selected); hideOrDisplayAudioRoutes(); } else if (id == R.id.route_speaker) { LinphoneManager.getInstance().routeAudioToSpeaker(); isSpeakerEnabled = true; routeBluetooth.setImageResource(R.drawable.route_bluetooth); routeSpeaker.setImageResource(R.drawable.route_speaker_selected); routeEarpiece.setImageResource(R.drawable.route_earpiece); hideOrDisplayAudioRoutes(); } else if (id == R.id.call_pause) { LinphoneCall call = (LinphoneCall) v.getTag(); pauseOrResumeCall(call); } else if (id == R.id.conference_pause) { pauseOrResumeConference(); } }
From source file:cl.gisred.android.MedidorActivity.java
private void verifPermisos() { if (ContextCompat.checkSelfPermission(MedidorActivity.this, Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED) { // Should we show an explanation? if (ActivityCompat.shouldShowRequestPermissionRationale(MedidorActivity.this, Manifest.permission.ACCESS_FINE_LOCATION)) { } else {/*from w ww.jav a 2 s .c om*/ // No explanation needed, we can request the permission. ActivityCompat.requestPermissions(MedidorActivity.this, new String[] { Manifest.permission.ACCESS_FINE_LOCATION }, Util.REQUEST_ACCESS_FINE_LOCATION); } } else { initGeoposition(); } }
From source file:cl.gisred.android.LectorActivity.java
private void verifPermisos() { if (ContextCompat.checkSelfPermission(LectorActivity.this, Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED) { // Should we show an explanation? if (ActivityCompat.shouldShowRequestPermissionRationale(LectorActivity.this, Manifest.permission.ACCESS_FINE_LOCATION)) { } else {//from w ww . ja va 2 s.com // No explanation needed, we can request the permission. ActivityCompat.requestPermissions(LectorActivity.this, new String[] { Manifest.permission.ACCESS_FINE_LOCATION }, Util.REQUEST_ACCESS_FINE_LOCATION); } } else { initGeoposition(); } }
From source file:com.seatgeek.placesautocompletedemo.MainFragment.java
private LatLng getLastKnownLocation(boolean isMoveMarker) { LocationManager lm = (LocationManager) TheApp.getAppContext().getSystemService(Context.LOCATION_SERVICE); Criteria criteria = new Criteria(); criteria.setAccuracy(Criteria.ACCURACY_LOW); String provider = lm.getBestProvider(criteria, true); if (provider == null) { return null; }/* w ww. j a va 2 s. c o m*/ Activity activity = getActivity(); if (activity == null) { return null; } if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) { if (activity.checkSelfPermission( Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED && activity.checkSelfPermission( Manifest.permission.ACCESS_COARSE_LOCATION) != PackageManager.PERMISSION_GRANTED) { return null; } } Location loc = lm.getLastKnownLocation(provider); if (loc != null) { LatLng latLng = new LatLng(loc.getLatitude(), loc.getLongitude()); if (isMoveMarker) { moveMarker(latLng); } return latLng; } return null; }
From source file:com.almalence.opencam.ApplicationScreen.java
@TargetApi(23) public void checkMicrophonePermission() { if (ContextCompat.checkSelfPermission(this, Manifest.permission.RECORD_AUDIO) != PackageManager.PERMISSION_GRANTED) { microphonePermissionGranted = false; // Should we show an explanation? if (ActivityCompat.shouldShowRequestPermissionRationale(this, Manifest.permission.RECORD_AUDIO)) { // 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. showRationaly(Manifest.permission.RECORD_AUDIO); } else {// ww w . j a v a2 s . co m // No explanation needed, we can request the permission. ActivityCompat.requestPermissions(this, new String[] { Manifest.permission.RECORD_AUDIO }, ApplicationScreen.MICROPHONE_PERMISSION_CODE); } } else microphonePermissionGranted = true; }
From source file:com.zertinteractive.wallpaper.MainActivity.java
private void checkPermission() { if (ActivityCompat.checkSelfPermission(this, Manifest.permission.WRITE_EXTERNAL_STORAGE) != PackageManager.PERMISSION_GRANTED) { // Check Permissions Now ActivityCompat.requestPermissions(this, new String[] { Manifest.permission.WRITE_EXTERNAL_STORAGE }, RC_PERMISSION_WRITE_EXTERNAL_STORAGE); } else {//from w ww .j ava2 s. co m // permission has been granted, continue as usual } }
From source file:net.gerosyab.dailylog.activity.MainActivity.java
@Override public void onRequestPermissionsResult(int requestCode, @NonNull String permissions[], @NonNull int[] grantResults) { switch (requestCode) { case FilePickerDialog.EXTERNAL_READ_PERMISSION_GRANT: { if (grantResults.length > 0 && grantResults[0] == PackageManager.PERMISSION_GRANTED) { if (dialog != null) { //Show dialog if the read permission has been granted. dialog.show();// w ww .j a v a 2 s . c o m } } else { //Permission has not been granted. Notify the user. Toast.makeText(MainActivity.this, "Permission is Required for getting list of files", Toast.LENGTH_SHORT).show(); } } } }
From source file:at.ac.tuwien.caa.docscan.ui.CameraActivity.java
private void requestPictureSave(byte[] data) { // Check if we have the permission to save images: if (ActivityCompat.checkSelfPermission(this, Manifest.permission.WRITE_EXTERNAL_STORAGE) != PackageManager.PERMISSION_GRANTED) { mPictureData = data;/*from ww w .jav a2 s . c o m*/ // ask for permission: ActivityCompat.requestPermissions(this, new String[] { Manifest.permission.WRITE_EXTERNAL_STORAGE }, PERMISSION_WRITE_EXTERNAL_STORAGE); } else savePicture(data); }
From source file:arc.noaa.weather.activities.MainActivity.java
void getCityByLocation() { locationManager = (LocationManager) getSystemService(LOCATION_SERVICE); if (ContextCompat.checkSelfPermission(this, Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED) { if (ActivityCompat.shouldShowRequestPermissionRationale(this, Manifest.permission.ACCESS_FINE_LOCATION)) { // Explanation not needed, since user requests this himself } else {// w w w. ja v a 2 s . co m ActivityCompat.requestPermissions(this, new String[] { Manifest.permission.ACCESS_FINE_LOCATION }, MY_PERMISSIONS_ACCESS_FINE_LOCATION); } } else if (locationManager.isProviderEnabled(LocationManager.NETWORK_PROVIDER) || locationManager.isProviderEnabled(LocationManager.GPS_PROVIDER)) { progressDialog = new ProgressDialog(this); progressDialog.setMessage(getString(R.string.getting_location)); progressDialog.setCancelable(false); progressDialog.setButton(DialogInterface.BUTTON_NEGATIVE, getString(R.string.dialog_cancel), new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialogInterface, int i) { try { locationManager.removeUpdates(MainActivity.this); } catch (SecurityException e) { e.printStackTrace(); } } }); progressDialog.show(); if (locationManager.isProviderEnabled(LocationManager.NETWORK_PROVIDER)) { locationManager.requestLocationUpdates(LocationManager.NETWORK_PROVIDER, 0, 0, this); } if (locationManager.isProviderEnabled(LocationManager.GPS_PROVIDER)) { locationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 0, 0, this); } } else { showLocationSettingsDialog(); } }