List of usage examples for android.content.pm PackageManager PERMISSION_DENIED
int PERMISSION_DENIED
To view the source code for android.content.pm PackageManager PERMISSION_DENIED.
Click Source Link
From source file:com.mikel.poseidon.Activities.preferences.BluetoothDeviceActivity.java
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); mContext = getApplicationContext();/*from ww w. j a v a2s . c o m*/ mSettings = mContext.getSharedPreferences(sharedPrefs, MODE_PRIVATE); mFragManager = getSupportFragmentManager(); setContentView(R.layout.activity_bluetooth); //callback to home button ImageButton home_buttod = (ImageButton) findViewById(R.id.homebutton); home_buttod.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { Intent home_inten = new Intent(BluetoothDeviceActivity.this, Menu.class); //home_intent5.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); home_inten.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP); startActivity(home_inten); } } ); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) { if (checkSelfPermission(Manifest.permission.ACCESS_FINE_LOCATION) == PackageManager.PERMISSION_DENIED) { Log.d("permission", "permission denied to ACCESS_FINE_LOCATION - requesting it"); String[] permissions = { Manifest.permission.ACCESS_FINE_LOCATION, Manifest.permission.ACCESS_COARSE_LOCATION }; requestPermissions(permissions, 1); } } mFragment = (BluetoothDeviceFragment) mFragManager.findFragmentById(R.id.bluetoothfragment); }
From source file:org.apache.cordova.nodialogspeechrecognizer.SpeechRecognizer.java
public void onRequestPermissionResult(int requestCode, String[] permissions, int[] grantResults) throws JSONException { for (int r : grantResults) { if (r == PackageManager.PERMISSION_DENIED) { this.callbackContext.error("No permission!"); return; }/* w w w . j ava2s . c o m*/ } promptForMic(new JSONArray()); }
From source file:com.google.samples.apps.iosched.util.PermissionsUtils.java
/** * Displays a {@link Snackbar} acknowledging the permission dismissal. If one of the permissions * is detected in the "Don't ask again" state then the OK button forwards to the AppInfo screen, * otherwise, the OK button invokes a permissions request. * <p/>//from ww w .ja v a 2 s. c o m * This method determines the Do-Not-Ask-Again-State by: 1.) Only being called from {@code * onRequestPermissionResult} when at least one permission was not granted. 2.) Checking that a * permission is currently in the permission-denied and no-rationale-needed states. 3.) The * combination of 1 and 2 indicates that at least one permission is in the Do-Not-Ask state and * the only resolution to that is for the user to visit the App Info -> Permissions screen. */ @NonNull public static Snackbar displayConditionalPermissionDenialSnackbar(@NonNull final Activity activity, final int messageResId, @NonNull String[] permissions, int requestCode, boolean isPersistent) { boolean permissionInDoNotAskAgainState = false; for (final String permission : permissions) { if (ActivityCompat.checkSelfPermission(activity, permission) == PackageManager.PERMISSION_DENIED && !ActivityCompat.shouldShowRequestPermissionRationale(activity, permission)) { permissionInDoNotAskAgainState = true; break; } } if (permissionInDoNotAskAgainState) { // User has to manually enable permissions on the AppInfo screen. return displayPermissionDeniedAppInfoResolutionSnackbar(activity, messageResId, isPersistent); } else { // User clicks OK to re-start the permissions requests. return displayPermissionRationaleSnackbar(activity, messageResId, permissions, requestCode, isPersistent); } }
From source file:com.onedrive.sdk.authentication.adal.BrokerPermissionsChecker.java
/** * Checks if the Broker has the permissions needed be used. * * @throws ClientAuthenticatorException If the required permissions are not available */// w w w . j a va 2 s. c om public void check() throws ClientAuthenticatorException { if (!AuthenticationSettings.INSTANCE.getSkipBroker()) { mLogger.logDebug("Checking permissions for use with the ADAL Broker."); for (final String permission : mBrokerRequirePermissions) { if (ContextCompat.checkSelfPermission(mContext, permission) == PackageManager.PERMISSION_DENIED) { final String message = String.format( "Required permissions to use the Broker are denied: %s, see %s for more details.", permission, mAdalProjectUrl); mLogger.logDebug(message); throw new ClientAuthenticatorException(message, OneDriveErrorCodes.AuthenicationPermissionsDenied); } } mLogger.logDebug("All required permissions found."); } }
From source file:com.djit.mixfader.sample.BaseActivity.java
/** * Handles permissions and features needed by the app *//*from w w w .j a v a2 s .co m*/ @Override protected void onResume() { super.onResume(); // Asks for Bluetooth activation is needed final BluetoothManager bluetoothManager = (BluetoothManager) getSystemService(Context.BLUETOOTH_SERVICE); final BluetoothAdapter bluetoothAdapter = bluetoothManager.getAdapter(); if (bluetoothAdapter == null || !bluetoothAdapter.isEnabled()) { final Intent enableBtIntent = new Intent(BluetoothAdapter.ACTION_REQUEST_ENABLE); startActivityForResult(enableBtIntent, REQUEST_ENABLE_BT); } // Asks for permissions if needed final int checkCoarseLocation = ContextCompat.checkSelfPermission(this, "android.permission.ACCESS_COARSE_LOCATION"); final int checkFineLocation = ContextCompat.checkSelfPermission(this, "android.permission.ACCESS_FINE_LOCATION"); if (checkCoarseLocation == PackageManager.PERMISSION_DENIED && checkFineLocation == PackageManager.PERMISSION_DENIED) { ActivityCompat.requestPermissions(this, new String[] { Manifest.permission.ACCESS_COARSE_LOCATION }, MY_PERMISSIONS_REQUEST_COARSE_LOCATION); } else { // Ask for location service if needed if (needToEnableLocation(this)) { final Intent viewIntent = new Intent(Settings.ACTION_LOCATION_SOURCE_SETTINGS); startActivity(viewIntent); } } }
From source file:org.jmpm.ethbadge.MainActivity.java
@Override protected void onCreate(Bundle savedInstanceState) { Thread.setDefaultUncaughtExceptionHandler(handleAppCrash); super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); try {/*from w ww . j av a2 s . co m*/ GlobalAppSettings.getInstance().initialize(getApplicationContext()); BluetoothAdapter mBluetoothAdapter = BluetoothAdapter.getDefaultAdapter(); if (!mBluetoothAdapter.isEnabled()) { Intent enableIntent = new Intent(BluetoothAdapter.ACTION_REQUEST_ENABLE); startActivityForResult(enableIntent, BluetoothConstants.REQUEST_ENABLE_BT); } } catch (Exception e) { Utils.sendFeedbackEmail(getApplicationContext(), (Exception) e); Toast.makeText(getApplicationContext(), GlobalAppConstants.UNEXPECTED_FATAL_EXCEPTION_MESSAGE, Toast.LENGTH_LONG).show(); } try { final AppCompatActivity myself = this; if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) { // Only ask for these permissions on runtime when running Android 6.0 or higher switch (ContextCompat.checkSelfPermission(getBaseContext(), Manifest.permission.ACCESS_COARSE_LOCATION)) { case PackageManager.PERMISSION_DENIED: ((TextView) new AlertDialog.Builder(this).setTitle("IMPORTANT").setMessage(Html.fromHtml( "<p>This app requires Bluetooth permissions to work. In addition, some devices require access to device's location permissions to find nearby Bluetooth devices. Please click \"Allow\" on the following runtime permissions popup.</p>" + "<p>For more info see <a href=\"http://developer.android.com/about/versions/marshmallow/android-6.0-changes.html#behavior-hardware-id\">here</a>.</p>")) .setNeutralButton("Okay", new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { if (ContextCompat.checkSelfPermission(getBaseContext(), Manifest.permission.ACCESS_COARSE_LOCATION) != PackageManager.PERMISSION_GRANTED) { int i = 5; ActivityCompat.requestPermissions(myself, new String[] { Manifest.permission.ACCESS_COARSE_LOCATION }, 1); } } }).show().findViewById(android.R.id.message)) .setMovementMethod(LinkMovementMethod.getInstance()); // Make the link clickable. Needs to be called after show(), in order to generate hyperlinks break; case PackageManager.PERMISSION_GRANTED: break; } } } catch (Exception e) { Utils.sendFeedbackEmail(getApplicationContext(), (Exception) e); Toast.makeText(getApplicationContext(), "Error: Could not set permissions", Toast.LENGTH_LONG).show(); } }
From source file:de.wolfgang_popp.shoppinglist.activity.SettingsFragment.java
@Override public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions, @NonNull int[] grantResults) { if (requestCode == REQUEST_CODE_EXT_STORAGE) { if (grantResults.length == 0 || grantResults[0] == PackageManager.PERMISSION_DENIED) { Toast.makeText(getActivity(), "permisson denied", Toast.LENGTH_SHORT).show(); PreferenceManager.getDefaultSharedPreferences(getActivity()).edit().putString(KEY_FILE_LOCATION, "") .commit();//w ww . j a v a 2 s .c om } } }
From source file:org.awesomeapp.messenger.ui.GalleryActivity.java
void startPhotoTaker() { int permissionCheck = ContextCompat.checkSelfPermission(this, Manifest.permission.CAMERA); if (permissionCheck == PackageManager.PERMISSION_DENIED) { // Should we show an explanation? if (ActivityCompat.shouldShowRequestPermissionRationale(this, Manifest.permission.CAMERA)) { View view = findViewById(R.id.gallery_fragment); // 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. Snackbar.make(view, R.string.grant_perms, Snackbar.LENGTH_LONG).show(); } else {/* w w w.ja v a2 s. co 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 { // create Intent to take a picture and return control to the calling application Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE); File photo = new File(Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DCIM), "cs_" + new Date().getTime() + ".jpg"); mLastPhoto = Uri.fromFile(photo); intent.putExtra(MediaStore.EXTRA_OUTPUT, mLastPhoto); // start the image capture Intent startActivityForResult(intent, ConversationDetailActivity.REQUEST_TAKE_PICTURE); } }
From source file:com.mattrayner.vuforia.VuforiaPlugin.java
public void onRequestPermissionResult(int requestCode, String[] permissions, int[] grantResults) throws JSONException { for (int r : grantResults) { if (r == PackageManager.PERMISSION_DENIED) { this.callback .sendPluginResult(new PluginResult(PluginResult.Status.ERROR, "CAMERA_PERMISSION_ERROR")); return; }// w ww .j av a2 s . co m } switch (requestCode) { case CAPTURE_VIDEO_ACTIVITY_REQUEST_CODE: execute(ACTION, ARGS, this.callback); break; } }
From source file:it.rignanese.leo.slimfacebook.PictureActivity.java
private void DownloadPicture(String url, boolean share) { //check permission if (Build.VERSION.SDK_INT >= 23 && ContextCompat.checkSelfPermission(this, android.Manifest.permission.WRITE_EXTERNAL_STORAGE) == PackageManager.PERMISSION_DENIED) { //ask permission Toast.makeText(getApplicationContext(), getString(R.string.acceptPermissionAndRetry), Toast.LENGTH_LONG) .show();/* w ww. j a v a2 s . com*/ int requestResult = 0; ActivityCompat.requestPermissions(this, new String[] { android.Manifest.permission.WRITE_EXTERNAL_STORAGE }, requestResult); } else { //download photo DownloadManager.Request request = new DownloadManager.Request(Uri.parse(url)); request.setTitle("SlimSocial Download"); // in order for this if to run, you must use the android 3.2 to compile your app if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) { request.allowScanningByMediaScanner(); request.setNotificationVisibility(DownloadManager.Request.VISIBILITY_VISIBLE_NOTIFY_COMPLETED); } String path = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_PICTURES).getPath(); if (savedPreferences.getBoolean("pref_useSlimSocialSubfolderToDownloadedFiles", false)) { path += "/SlimSocial"; } request.setDestinationInExternalPublicDir(path, "SlimSocial.jpg"); if (share) request.setNotificationVisibility(DownloadManager.Request.VISIBILITY_HIDDEN); // get download service and enqueue file long _idDownloadedFile = downloadManager.enqueue(request); if (share) idDownloadedFile = _idDownloadedFile; else Toast.makeText(getApplicationContext(), getString(R.string.downloadingPhoto), Toast.LENGTH_LONG) .show(); } }