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:android.zetterstrom.com.snow.fragments.SnowFragment.java
@Override public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions, @NonNull int[] grantResults) { switch (requestCode) { case COARSE_PERMISSION_REQUEST_CODE: { if (grantResults.length > 0 && grantResults[0] == PackageManager.PERMISSION_GRANTED) { // Permission is granted; use checkPermission to initiate the call to findLocation checkPermission();/*from www . j a v a 2 s . c o m*/ } else { handleDeniedPermission(); } break; } } }
From source file:co.ldln.android.MapFragment.java
private void checkPermissionsAndLoadOfflineMaps() { // Here, thisActivity is the current activity if (ContextCompat.checkSelfPermission(mActivity, Manifest.permission.READ_EXTERNAL_STORAGE) != PackageManager.PERMISSION_GRANTED) { // Should we show an explanation? if (ActivityCompat.shouldShowRequestPermissionRationale(mActivity, Manifest.permission.READ_EXTERNAL_STORAGE)) { // 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 {//from ww w .ja v a2 s. com // No explanation needed, we can request the permission. requestPermissions(new String[] { Manifest.permission.READ_EXTERNAL_STORAGE }, 100); // MY_PERMISSIONS_REQUEST_READ_CONTACTS is an // app-defined int constant. The callback method gets the // result of the request. // TODO: Determine if this is ever actually needed on any devices/OSs } } else { // Permission was previously granted, can just continue to loading the maps loadOfflineMaps(); } }
From source file:cc.metapro.openct.allclasses.ExcelDialog.java
@NonNull @Override/* www .j av a 2 s.com*/ public Dialog onCreateDialog(Bundle savedInstanceState) { final AlertDialog dialog = new AlertDialog.Builder(getActivity()).setTitle(R.string.import_from_excel) .setMessage(R.string.select_file_tip).setPositiveButton(R.string.select_file, null) .setNegativeButton(android.R.string.cancel, null) .setNeutralButton(R.string.refer_to_usage, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { Intent intent = new Intent(Intent.ACTION_VIEW); intent.setData(Uri .parse("https://github.com/jeffreystoke/openct-mvp#import-from-xlsx-excel-2007")); startActivity(intent); } }).create(); dialog.setOnShowListener(new DialogInterface.OnShowListener() { @Override public void onShow(DialogInterface dialog) { Button positiveButton = ((AlertDialog) dialog).getButton(AlertDialog.BUTTON_POSITIVE); positiveButton.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) { int hasPermission = ContextCompat.checkSelfPermission(getActivity(), Manifest.permission.WRITE_EXTERNAL_STORAGE); if (hasPermission != PackageManager.PERMISSION_GRANTED) { requestPermissions(new String[] { Manifest.permission.WRITE_EXTERNAL_STORAGE }, REQUEST_EXTERNAL_FILE_WRITE); } else { showFilerChooser(); } } else { showFilerChooser(); } } }); } }); return dialog; }
From source file:casariego.jorge.createpdf.Pdf1Activity.java
@Override public void onRequestPermissionsResult(int requestCode, String permissions[], int[] grantResults) { switch (requestCode) { case REQUEST_EXTERNAL_STORAGE: { // If request is cancelled, the result arrays are empty. if (grantResults.length > 0 && grantResults[0] == PackageManager.PERMISSION_GRANTED) { // permission was granted, yay! Do the // contacts-related task you need to do. createPDF();/*from w w w . ja v a 2 s . c om*/ } else { // permission denied, boo! Disable the // functionality that depends on this permission. Toast.makeText(Pdf1Activity.this, "No podemos escribir sin tener permiso", Toast.LENGTH_SHORT) .show(); } return; } // other 'case' lines to check for other // permissions this app might request } }
From source file:de.lespace.apprtc.activity.ConnectActivity.java
@Override public void onRequestPermissionsResult(int requestCode, String permissions[], int[] grantResults) { if (grantResults.length > 0 && grantResults[0] == PackageManager.PERMISSION_GRANTED) { Log.e(TAG, MANDATORY_PERMISSIONS[0] + " Permission Granted!"); } else {/*from ww w . ja v a2 s . co m*/ Log.e(TAG, MANDATORY_PERMISSIONS[0] + " Permission Denied!"); } missingPermissions.remove(0); //remove missing permission from array and request next left permission requestPermission(); }
From source file:at.ac.tuwien.caa.docscan.camera.LocationHandler.java
private LocationHandler(Context context) { mContext = context;/* w w w . j a v a 2 s . co m*/ mLocationManager = (LocationManager) mContext.getSystemService(Context.LOCATION_SERVICE); LocationListener locationListener = new LocationListener() { public void onLocationChanged(Location location) { boolean stopManager = false; // Called when a new location is found: if (isBetterLocation(location, mLocation)) { mLocation = location; if (mLocation.getAccuracy() <= MIN_ACCURACY) stopManager = true; } if (System.currentTimeMillis() - mStartTime >= MAX_TIME_RUNNING) stopManager = true; if (stopManager && ActivityCompat.checkSelfPermission(mContext, Manifest.permission.ACCESS_FINE_LOCATION) == PackageManager.PERMISSION_GRANTED) mLocationManager.removeUpdates(this); } public void onStatusChanged(String provider, int status, Bundle extras) { } public void onProviderEnabled(String provider) { } public void onProviderDisabled(String provider) { } }; if (ActivityCompat.checkSelfPermission(mContext, Manifest.permission.ACCESS_FINE_LOCATION) == PackageManager.PERMISSION_GRANTED) { List<String> providers = mLocationManager.getProviders(true); if (providers.contains(LocationManager.NETWORK_PROVIDER)) mLocationManager.requestLocationUpdates(LocationManager.NETWORK_PROVIDER, UPDATE_TIME, UPDATE_DISTANCE, locationListener); if (providers.contains(LocationManager.GPS_PROVIDER)) mLocationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, UPDATE_TIME, UPDATE_DISTANCE, locationListener); mStartTime = System.currentTimeMillis(); } }
From source file:at.bitfire.nophonespam.BlacklistActivity.java
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_blacklist); settings = new Settings(this); list = (ListView) findViewById(R.id.numbers); list.setAdapter(adapter = new NumberAdapter(this)); list.setOnItemClickListener(this); list.setChoiceMode(ListView.CHOICE_MODE_MULTIPLE_MODAL); list.setMultiChoiceModeListener(new AbsListView.MultiChoiceModeListener() { @Override//from www. j a v a2 s.c om public void onItemCheckedStateChanged(ActionMode actionMode, int position, long id, boolean checked) { } @Override public boolean onCreateActionMode(ActionMode actionMode, Menu menu) { getMenuInflater().inflate(R.menu.blacklist_delete_numbers, menu); return true; } @Override public boolean onPrepareActionMode(ActionMode actionMode, Menu menu) { return false; } @Override public boolean onActionItemClicked(ActionMode actionMode, MenuItem menuItem) { switch (menuItem.getItemId()) { case R.id.delete: deleteSelectedNumbers(); actionMode.finish(); return true; } return false; } @Override public void onDestroyActionMode(ActionMode actionMode) { } }); if (ContextCompat.checkSelfPermission(this, Manifest.permission.CALL_PHONE) != PackageManager.PERMISSION_GRANTED || ContextCompat.checkSelfPermission(this, Manifest.permission.READ_PHONE_STATE) != PackageManager.PERMISSION_GRANTED) ActivityCompat.requestPermissions(this, new String[] { Manifest.permission.CALL_PHONE, Manifest.permission.READ_PHONE_STATE }, 0); getLoaderManager().initLoader(0, null, this); }
From source file:com.remobile.cordova.CordovaInterface.java
public boolean hasPermission(String permission) { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) { int result = getActivity().checkSelfPermission(permission); return PackageManager.PERMISSION_GRANTED == result; } else {//www . j av a2 s . co m return true; } }
From source file:in.codehex.arrow.LoginActivity.java
/** * Implement and manipulate the objects/*w ww . j a v a 2s . com*/ */ private void prepareObjects() { progressDialog.setMessage("Authenticating.."); progressDialog.setCancelable(false); fab.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { name = editName.getText().toString().trim(); phone = editPhone.getText().toString().trim(); // marshmallow runtime Telephone permission if (ContextCompat.checkSelfPermission(getApplicationContext(), Manifest.permission.READ_PHONE_STATE) == PackageManager.PERMISSION_GRANTED) { imei = telephonyManager.getDeviceId(); processData(); } else if (ContextCompat.checkSelfPermission(getApplicationContext(), Manifest.permission.READ_PHONE_STATE) != PackageManager.PERMISSION_GRANTED) { ActivityCompat.requestPermissions(LoginActivity.this, new String[] { Manifest.permission.READ_PHONE_STATE }, Config.PERMISSION_READ_PHONE_STATE); } } }); }
From source file:com.aitorvs.android.eyetoggle.MainActivity.java
/** * Check camera permission//from w w w. j a v a2 s .c om * * @return <code>true</code> if granted */ private boolean isCameraPermissionGranted() { return ActivityCompat.checkSelfPermission(this, Manifest.permission.CAMERA) == PackageManager.PERMISSION_GRANTED; }