List of usage examples for android.support.v4.content PermissionChecker checkSelfPermission
public static int checkSelfPermission(@NonNull Context context, @NonNull String permission)
From source file:com.prey.PreyPermission.java
public static boolean canAccessReadSms(Context ctx) { boolean canAccessReadSms = PermissionChecker.checkSelfPermission(ctx, Manifest.permission.READ_SMS) == PermissionChecker.PERMISSION_GRANTED; //PreyLogger.d("canAccessReadSms:"+canAccessReadSms); return canAccessReadSms; }
From source file:com.tozny.e3db.android.KeyStoreManager.java
@SuppressLint({ "MissingPermission", "NewApi" }) private static void checkArgs(Context context, KeyAuthentication protection, KeyAuthenticator keyAuthenticator) { if (Build.VERSION.SDK_INT < Build.VERSION_CODES.M) { if (protection.authenticationType() == FINGERPRINT || protection.authenticationType() == LOCK_SCREEN) throw new IllegalArgumentException( protection.authenticationType().toString() + " not supported below API 23."); }/*from w w w . j a v a 2 s .c o m*/ if (protection.authenticationType() == PASSWORD || protection.authenticationType() == FINGERPRINT || protection.authenticationType() == LOCK_SCREEN) { if (keyAuthenticator == null) { throw new IllegalArgumentException("KeyAuthenticator can't be null for key protection type: " + protection.authenticationType().toString()); } } if (protection.authenticationType() == FINGERPRINT) { if (PermissionChecker.checkSelfPermission(context, Manifest.permission.USE_FINGERPRINT) != PermissionChecker.PERMISSION_GRANTED) throw new IllegalArgumentException( protection.authenticationType().toString() + " permission not granted."); // Some devices support fingerprint but the support library doesn't recognize it, so // we use the actual FingerprintManager here. (https://stackoverflow.com/a/45181416/169359) FingerprintManager mgr = context.getSystemService(FingerprintManager.class); if (mgr == null || !mgr.isHardwareDetected()) throw new IllegalArgumentException( protection.authenticationType().toString() + " hardware not available."); } if (protection.authenticationType() == LOCK_SCREEN) { if (protection.validUntilSecondsSinceUnlock() < 1) throw new IllegalArgumentException("secondsSinceUnlock must be greater than 0."); } }
From source file:com.ultramegasoft.flavordex2.util.PermissionUtils.java
/** * Check whether we have permission to read and write external storage. * * @param context The Context//from ww w . ja v a 2 s .c o m * @return Whether we have permission to read and write external storage */ public static boolean hasExternalStoragePerm(@NonNull Context context) { return PermissionChecker.checkSelfPermission(context, Manifest.permission.WRITE_EXTERNAL_STORAGE) == PermissionChecker.PERMISSION_GRANTED; }
From source file:com.prey.PreyPermission.java
public static boolean canAccessReadExternalStorage(Context ctx) { boolean canAccessReadExternalStorage = PermissionChecker.checkSelfPermission(ctx, Manifest.permission.READ_EXTERNAL_STORAGE) == PermissionChecker.PERMISSION_GRANTED; //PreyLogger.d("canAccessReadExternalStorage:"+canAccessReadExternalStorage); return canAccessReadExternalStorage; }
From source file:com.yanzhenjie.album.mvp.BaseActivity.java
private static List<String> getDeniedPermissions(Context context, String... permissions) { List<String> deniedList = new ArrayList<>(2); for (String permission : permissions) { if (PermissionChecker.checkSelfPermission(context, permission) != PermissionChecker.PERMISSION_GRANTED) { deniedList.add(permission);/*from w w w.j ava 2 s . c o m*/ } } return deniedList; }
From source file:com.example.captain_miao.grantap.utils.PermissionUtils.java
@TargetApi(value = Build.VERSION_CODES.M) public static List<String> findDeniedPermissions(Activity activity, String... permission) { List<String> denyPermissions = new ArrayList<>(); for (String value : permission) { // CommonsWare's blog post:https://commonsware.com/blog/2015/08/17/random-musings-android-6p0-sdk.html //support SYSTEM_ALERT_WINDOW,WRITE_SETTINGS if (isOverMarshmallow() && value.equals(Manifest.permission.SYSTEM_ALERT_WINDOW)) { if (!Settings.canDrawOverlays(activity)) { denyPermissions.add(value); }//from www . j a v a 2 s . c o m } else if (isOverMarshmallow() && value.equals(Manifest.permission.WRITE_SETTINGS)) { if (!Settings.System.canWrite(activity)) { denyPermissions.add(value); } } //else if (activity.checkSelfPermission(value) != PackageManager.PERMISSION_GRANTED) { // denyPermissions.add(value); //} else if (PermissionChecker.checkSelfPermission(activity, value) != PackageManager.PERMISSION_GRANTED) { denyPermissions.add(value); } } return denyPermissions; }
From source file:android.support.v7.app.TwilightManager.java
private Location getLastKnownLocation() { Location coarseLoc = null;//from w w w . j ava 2 s . c om Location fineLoc = null; int permission = PermissionChecker.checkSelfPermission(mContext, Manifest.permission.ACCESS_COARSE_LOCATION); if (permission == PermissionChecker.PERMISSION_GRANTED) { coarseLoc = getLastKnownLocationForProvider(LocationManager.NETWORK_PROVIDER); } permission = PermissionChecker.checkSelfPermission(mContext, Manifest.permission.ACCESS_FINE_LOCATION); if (permission == PermissionChecker.PERMISSION_GRANTED) { fineLoc = getLastKnownLocationForProvider(LocationManager.GPS_PROVIDER); } if (fineLoc != null && coarseLoc != null) { // If we have both a fine and coarse location, use the latest return fineLoc.getTime() > coarseLoc.getTime() ? fineLoc : coarseLoc; } else { // Else, return the non-null one (if there is one) return fineLoc != null ? fineLoc : coarseLoc; } }
From source file:org.deviceconnect.android.deviceplugin.hvcc2w.setting.fragment.HVCC2WPairingFragment.java
/** Check Permission. */ private void checkPermission() { // WiFi scan requires location permissions. if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP + 1) { if (PermissionChecker.checkSelfPermission(getContext(), Manifest.permission.ACCESS_COARSE_LOCATION) == PackageManager.PERMISSION_GRANTED && PermissionChecker.checkSelfPermission(getContext(), Manifest.permission.ACCESS_FINE_LOCATION) == PackageManager.PERMISSION_GRANTED) { searchWifi();/*from ww w . j av a 2 s .c om*/ } else { PermissionRequestActivity.requestPermissions(getContext(), new String[] { Manifest.permission.ACCESS_COARSE_LOCATION, Manifest.permission.ACCESS_FINE_LOCATION }, new ResultReceiver(new Handler(Looper.getMainLooper())) { @Override protected void onReceiveResult(final int resultCode, final Bundle resultData) { String[] retPermissions = resultData.getStringArray("EXTRA_PERMISSIONS"); int[] retGrantResults = resultData.getIntArray("EXTRA_GRANT_RESULTS"); if (retPermissions == null || retGrantResults == null) { HVCC2WDialogFragment.showAlert(getActivity(), getString(R.string.hw_name), "WiFi scan aborted.", null); return; } for (int i = 0; i < retPermissions.length; ++i) { if (retGrantResults[i] == PackageManager.PERMISSION_DENIED) { HVCC2WDialogFragment.showAlert(getActivity(), getString(R.string.hw_name), "WiFi scan aborted.", null); return; } } searchWifi(); } }); } } }
From source file:com.tct.mail.browse.EmlViewerActivity.java
@Override public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions, @NonNull int[] grantResults) { if (PermissionUtil.REQ_CODE_PERMISSION_RESULT == requestCode) { boolean granted = true; for (String permission : permissions) { if (PermissionChecker.checkSelfPermission(this, permission) != PackageManager.PERMISSION_GRANTED) { granted = false;// www .j a va2s . c o m this.finish(); break; } } if (granted) { doCreate(null); } else { //[BUGFIX]-MOD by SCDTABLET.shujing.jin@tcl.com,08/05/2016,2635083 Utility.showToast(this, R.string.no_permission_to_open_file); //Toast.makeText(this, R.string.no_permission_to_open_file, Toast.LENGTH_LONG).show(); } } }
From source file:com.tozny.e3db.android.KeyAuthentication.java
/** * Indicates if the device and SDK support the given type of key authentication. * @param ctx Application context./*ww w.j a v a 2s.co m*/ * @param authentication Authentication type. * @return {@code true} if the authencation type is supported; {@code false} otherwise. */ @SuppressLint("MissingPermission") public static boolean protectionTypeSupported(Context ctx, KeyAuthenticationType authentication) { switch (authentication) { case NONE: case PASSWORD: return true; case LOCK_SCREEN: return Build.VERSION.SDK_INT >= Build.VERSION_CODES.M; case FINGERPRINT: if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) { // Some devices support fingerprint but the support library doesn't recognize it, so // we use the actual FingerprintManager here. (https://stackoverflow.com/a/45181416/169359) FingerprintManager mgr = ctx.getSystemService(FingerprintManager.class); if (mgr != null) { return PermissionChecker.checkSelfPermission(ctx, Manifest.permission.USE_FINGERPRINT) == PermissionChecker.PERMISSION_GRANTED && mgr.isHardwareDetected() && mgr.hasEnrolledFingerprints(); } } return false; default: throw new IllegalStateException("Unhandled authentication type: " + authentication); } }