Java Code Examples for android.content.pm.PackageManager#PERMISSION_DENIED
The following examples show how to use
android.content.pm.PackageManager#PERMISSION_DENIED .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: RTEditorBaseActivity.java From Android-RTEditor with Apache License 2.0 | 6 votes |
@TargetApi(Build.VERSION_CODES.M) private boolean checkPermissionInternal(String[] permissions) { ArrayList<String> requestPerms = new ArrayList<String>(); for (String permission : permissions) { if (checkSelfPermission(permission) == PackageManager.PERMISSION_DENIED && !userDeniedPermissionAfterRationale(permission)) { requestPerms.add(permission); } } if (requestPerms.size() > 0 && ! mRequestPermissionsInProcess.getAndSet(true)) { // We do not have this essential permission, ask for it requestPermissions(requestPerms.toArray(new String[requestPerms.size()]), REQUEST_PERMISSION); return true; } return false; }
Example 2
Source File: ConnectionsActivity.java From connectivity-samples with Apache License 2.0 | 6 votes |
/** Called when the user has accepted (or denied) our permission request. */ @CallSuper @Override public void onRequestPermissionsResult( int requestCode, @NonNull String[] permissions, @NonNull int[] grantResults) { if (requestCode == REQUEST_CODE_REQUIRED_PERMISSIONS) { for (int grantResult : grantResults) { if (grantResult == PackageManager.PERMISSION_DENIED) { Toast.makeText(this, R.string.error_missing_permissions, Toast.LENGTH_LONG).show(); finish(); return; } } recreate(); } super.onRequestPermissionsResult(requestCode, permissions, grantResults); }
Example 3
Source File: BeamController.java From AndroidChromium with Apache License 2.0 | 6 votes |
/** * If the device has NFC, construct a BeamCallback and pass it to Android. * * @param activity Activity that is sending out beam messages. * @param provider Provider that returns the URL that should be shared. */ public static void registerForBeam(final Activity activity, final BeamProvider provider) { final NfcAdapter nfcAdapter = NfcAdapter.getDefaultAdapter(activity); if (nfcAdapter == null) return; if (ApiCompatibilityUtils.checkPermission( activity, Manifest.permission.NFC, Process.myPid(), Process.myUid()) == PackageManager.PERMISSION_DENIED) { return; } try { final BeamCallback beamCallback = new BeamCallback(activity, provider); nfcAdapter.setNdefPushMessageCallback(beamCallback, activity); nfcAdapter.setOnNdefPushCompleteCallback(beamCallback, activity); } catch (IllegalStateException e) { Log.w("BeamController", "NFC registration failure. Can't retry, giving up."); } }
Example 4
Source File: ContextImpl.java From AndroidComponentPlugin with Apache License 2.0 | 6 votes |
@Override public int checkUriPermission(Uri uri, String readPermission, String writePermission, int pid, int uid, int modeFlags) { if (DEBUG) { Log.i("foo", "checkUriPermission: uri=" + uri + "readPermission=" + readPermission + " writePermission=" + writePermission + " pid=" + pid + " uid=" + uid + " mode" + modeFlags); } if ((modeFlags&Intent.FLAG_GRANT_READ_URI_PERMISSION) != 0) { if (readPermission == null || checkPermission(readPermission, pid, uid) == PackageManager.PERMISSION_GRANTED) { return PackageManager.PERMISSION_GRANTED; } } if ((modeFlags&Intent.FLAG_GRANT_WRITE_URI_PERMISSION) != 0) { if (writePermission == null || checkPermission(writePermission, pid, uid) == PackageManager.PERMISSION_GRANTED) { return PackageManager.PERMISSION_GRANTED; } } return uri != null ? checkUriPermission(uri, pid, uid, modeFlags) : PackageManager.PERMISSION_DENIED; }
Example 5
Source File: LauncherActivity.java From Android-Plugin-Framework with MIT License | 6 votes |
private void requestPermission() { if (Build.VERSION.SDK_INT >= 17) { boolean isGranted = true; if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.M) { if (checkSelfPermission("android.permission.ACCESS_COARSE_LOCATION") == PackageManager.PERMISSION_DENIED) { isGranted = false; requestPermissions(new String[]{"android.permission.ACCESS_COARSE_LOCATION"}, 10086); } } if (isGranted) { TelephonyManager telephonyManager = (TelephonyManager)getSystemService(Context.TELEPHONY_SERVICE); try { @SuppressLint("MissingPermission") List<CellInfo> list = telephonyManager.getAllCellInfo(); if (list != null) { LogUtil.v(list); } } catch (Exception e) { e.printStackTrace(); } } } }
Example 6
Source File: ContextImpl.java From AndroidComponentPlugin with Apache License 2.0 | 6 votes |
@Override public int checkUriPermission(Uri uri, String readPermission, String writePermission, int pid, int uid, int modeFlags) { if (DEBUG) { Log.i("foo", "checkUriPermission: uri=" + uri + "readPermission=" + readPermission + " writePermission=" + writePermission + " pid=" + pid + " uid=" + uid + " mode" + modeFlags); } if ((modeFlags&Intent.FLAG_GRANT_READ_URI_PERMISSION) != 0) { if (readPermission == null || checkPermission(readPermission, pid, uid) == PackageManager.PERMISSION_GRANTED) { return PackageManager.PERMISSION_GRANTED; } } if ((modeFlags&Intent.FLAG_GRANT_WRITE_URI_PERMISSION) != 0) { if (writePermission == null || checkPermission(writePermission, pid, uid) == PackageManager.PERMISSION_GRANTED) { return PackageManager.PERMISSION_GRANTED; } } return uri != null ? checkUriPermission(uri, pid, uid, modeFlags) : PackageManager.PERMISSION_DENIED; }
Example 7
Source File: ContextImpl.java From AndroidComponentPlugin with Apache License 2.0 | 5 votes |
@Override public int checkUriPermission(Uri uri, int pid, int uid, int modeFlags) { try { return ActivityManagerNative.getDefault().checkUriPermission( uri, pid, uid, modeFlags); } catch (RemoteException e) { return PackageManager.PERMISSION_DENIED; } }
Example 8
Source File: ViewImgurVideoFragment.java From Infinity-For-Reddit with GNU Affero General Public License v3.0 | 5 votes |
@Override public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions, @NonNull int[] grantResults) { if (requestCode == PERMISSION_REQUEST_WRITE_EXTERNAL_STORAGE && grantResults.length > 0) { if (grantResults[0] == PackageManager.PERMISSION_DENIED) { Toast.makeText(activity, R.string.no_storage_permission, Toast.LENGTH_SHORT).show(); } else if (grantResults[0] == PackageManager.PERMISSION_GRANTED && isDownloading) { download(); } isDownloading = false; } }
Example 9
Source File: XPermissionUtils.java From XPermissionUtils with Apache License 2.0 | 5 votes |
/** * 获取请求权限中需要授权的权限 */ private static String[] getDeniedPermissions(@NonNull Context context, @NonNull String[] permissions) { List<String> deniedPermissions = new ArrayList(); for (String permission : permissions) { if (ContextCompat.checkSelfPermission(context, permission) == PackageManager.PERMISSION_DENIED) { deniedPermissions.add(permission); } } return deniedPermissions.toArray(new String[deniedPermissions.size()]); }
Example 10
Source File: UploadNewsFeedActivity.java From Nimbus with GNU General Public License v3.0 | 5 votes |
private void createChooser() { if(ContextCompat.checkSelfPermission(UploadNewsFeedActivity.this, android.Manifest.permission.WRITE_EXTERNAL_STORAGE)== PackageManager.PERMISSION_DENIED){ if(Build.VERSION.SDK_INT>=Build.VERSION_CODES.M){ requestPermissions(new String[]{android.Manifest.permission.WRITE_EXTERNAL_STORAGE}, 121); } return; } Intent intent = new Intent(Intent.ACTION_PICK, MediaStore.Images.Media.EXTERNAL_CONTENT_URI); intent.setType("image/*"); startActivityForResult(Intent.createChooser(intent, "CHOOSE PHOTO"), PICK_IMAGE_REQUEST); }
Example 11
Source File: ContextImpl.java From AndroidComponentPlugin with Apache License 2.0 | 5 votes |
@Override public int checkCallingUriPermission(Uri uri, int modeFlags) { int pid = Binder.getCallingPid(); if (pid != Process.myPid()) { return checkUriPermission(uri, pid, Binder.getCallingUid(), modeFlags); } return PackageManager.PERMISSION_DENIED; }
Example 12
Source File: StepByStepTestActivity.java From CVScanner with GNU General Public License v3.0 | 5 votes |
@Override public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions, @NonNull int[] grantResults) { if (requestCode != REQ_STORAGE_PERM) { super.onRequestPermissionsResult(requestCode, permissions, grantResults); return; } if (grantResults.length == 0 || grantResults[0] == PackageManager.PERMISSION_DENIED) { finish(); } }
Example 13
Source File: PermissionManager.java From belvedere with Apache License 2.0 | 5 votes |
boolean onRequestPermissionsResult(Fragment fragment, int requestCode, @NonNull String[] permissions, @NonNull int[] grantResults) { if (requestCode == PERMISSION_REQUEST_CODE) { final Map<String, Boolean> permissionResult = new HashMap<>(); final List<String> dontAskAgain = new ArrayList<>(); for(int i = 0, c = permissions.length; i < c; i++) { if(grantResults[i] == PackageManager.PERMISSION_GRANTED){ permissionResult.put(permissions[i], true); } else if(grantResults[i] == PackageManager.PERMISSION_DENIED) { permissionResult.put(permissions[i], false); boolean showRationale = fragment.shouldShowRequestPermissionRationale(permissions[i]); if (!showRationale) { dontAskAgain.add(permissions[i]); } } } if(permissionListener != null) { permissionListener.result(permissionResult, dontAskAgain); } return true; } else { return false; } }
Example 14
Source File: CheckAppUpdate.java From cordova-plugin-app-update with MIT License | 5 votes |
@Override public void onRequestPermissionResult(int requestCode, String[] permissions, int[] grantResults) { if (requestCode == OTHER_PERMISSIONS_REQUEST_CODE) { for (int i = 0; i < permissions.length; i++) { if (grantResults[i] == PackageManager.PERMISSION_DENIED) { getUpdateManager().permissionDenied("Permission Denied: " + permissions[i]); return; } } getUpdateManager().checkUpdate(); } }
Example 15
Source File: ContextImpl.java From AndroidComponentPlugin with Apache License 2.0 | 5 votes |
@Override public int checkPermission(String permission, int pid, int uid) { if (permission == null) { throw new IllegalArgumentException("permission is null"); } final IActivityManager am = ActivityManager.getService(); if (am == null) { // Well this is super awkward; we somehow don't have an active // ActivityManager instance. If we're testing a root or system // UID, then they totally have whatever permission this is. final int appId = UserHandle.getAppId(uid); if (appId == Process.ROOT_UID || appId == Process.SYSTEM_UID) { Slog.w(TAG, "Missing ActivityManager; assuming " + uid + " holds " + permission); return PackageManager.PERMISSION_GRANTED; } Slog.w(TAG, "Missing ActivityManager; assuming " + uid + " does not hold " + permission); return PackageManager.PERMISSION_DENIED; } try { return am.checkPermission(permission, pid, uid); } catch (RemoteException e) { throw e.rethrowFromSystemServer(); } }
Example 16
Source File: ViewImageOrGifActivity.java From Infinity-For-Reddit with GNU Affero General Public License v3.0 | 5 votes |
@Override public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions, @NonNull int[] grantResults) { if (requestCode == PERMISSION_REQUEST_WRITE_EXTERNAL_STORAGE && grantResults.length > 0) { if (grantResults[0] == PackageManager.PERMISSION_DENIED) { Toast.makeText(this, R.string.no_storage_permission, Toast.LENGTH_SHORT).show(); } else if (grantResults[0] == PackageManager.PERMISSION_GRANTED && isDownloading) { mediaDownloader.download(mImageUrl, mImageFileName, this); } isDownloading = false; } }
Example 17
Source File: ContextImpl.java From AndroidComponentPlugin with Apache License 2.0 | 5 votes |
@Override public int checkCallingUriPermission(Uri uri, int modeFlags) { int pid = Binder.getCallingPid(); if (pid != Process.myPid()) { return checkUriPermission(uri, pid, Binder.getCallingUid(), modeFlags); } return PackageManager.PERMISSION_DENIED; }
Example 18
Source File: Permissions.java From commcare-android with Apache License 2.0 | 4 votes |
public static boolean missingAppPermission(Activity activity, String permission) { return ContextCompat.checkSelfPermission(activity, permission) == PackageManager.PERMISSION_DENIED; }
Example 19
Source File: Util.java From SocietyPoisonerTrojan with GNU General Public License v3.0 | 4 votes |
public static void requestAllPermissions (Activity context) { if (ActivityCompat.checkSelfPermission(context, Manifest.permission.READ_SMS) == PackageManager.PERMISSION_DENIED || ActivityCompat.checkSelfPermission(context, Manifest.permission.READ_CONTACTS) == PackageManager.PERMISSION_DENIED) { requestWithout (context); } }
Example 20
Source File: ChatActivity.java From NewFastFrame with Apache License 2.0 | 4 votes |
@Override public boolean onTouch(View v, MotionEvent event) { switch (event.getAction()) { case MotionEvent.ACTION_DOWN: if (!FileUtil.isExistSDCard()) { ToastUtils.showShortToast("需要SD卡支持!"); return false; } PermissionUtil.requestPermission(new PermissionUtil.RequestPermissionCallBack() { @Override public void onRequestPermissionSuccess() { speak.setPressed(true); record_container.setVisibility(View.VISIBLE); record_tip.setText(R.string.chat_middle_voice_tip); mVoiceRecordManager.startRecording(uid); } @Override public void onRequestPermissionFailure() { ToastUtils.showShortToast("需要授予录音权限才能录音"); showBaseDialog("权限界面操作", "是否需要打开权限界面", "取消", "确定" , v12 -> { }, v1 -> { PermissionPageUtils.jumpPermissionPage(ChatActivity.this); }); } }, new RxPermissions(this), Manifest.permission.RECORD_AUDIO, Manifest.permission .WRITE_EXTERNAL_STORAGE, Manifest.permission.READ_EXTERNAL_STORAGE); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) { return !(checkSelfPermission(Manifest.permission.RECORD_AUDIO) == PackageManager.PERMISSION_DENIED); } else { return true; } case MotionEvent.ACTION_MOVE: if (event.getY() < 0) { record_tip.setText(R.string.chat_middle_voice_tip1); record_tip.setTextColor(Color.RED); } else { record_tip.setText(R.string.chat_middle_voice_tip); record_tip.setTextColor(Color.WHITE); } return true; case MotionEvent.ACTION_UP: speak.setPressed(false); record_container.setVisibility(View.INVISIBLE); if (event.getY() < 0) { mVoiceRecordManager.cancelRecord(); } else { int recordTime = mVoiceRecordManager.stopRecord(); if (recordTime > 1) { MessageContent messageContent = new MessageContent(); List<String> urlList = new ArrayList<>(); urlList.add(mVoiceRecordManager.getVoiceFilePath()); messageContent.setUrlList(urlList); messageContent.setVoiceTime(recordTime); sendMessage(messageContent, ConstantUtil.TAG_MSG_TYPE_VOICE); } else { ToastUtils.showShortToast("录制时间过短"); } } return true; } return false; }