List of usage examples for android.content Context checkPermission
@CheckResult(suggest = "#enforcePermission(String,int,int,String)") @PackageManager.PermissionResult public abstract int checkPermission(@NonNull String permission, int pid, int uid);
From source file:Main.java
public static boolean checkPermission(Context context) { return context.checkPermission(Manifest.permission.CAMERA, Process.myPid(), Process.myUid()) == PackageManager.PERMISSION_GRANTED; }
From source file:Main.java
public static boolean hasPermission(Context context, String permission) { return context.checkPermission(permission, Process.myPid(), Process.myUid()) == PackageManager.PERMISSION_GRANTED; }
From source file:Main.java
public static boolean hasPermission(Context context, String permission) { if ((context == null) || (permission == null)) { return false; }/*from w w w. j ava 2 s . c o m*/ return context.checkPermission(permission, Process.myPid(), Process.myUid()) == 0; }
From source file:com.brainasylum.andruid.UniqueIdentifierManager.java
private static boolean canWriteExternalStorage(Context context) { return (context.checkPermission("android.permission.WRITE_EXTERNAL_STORAGE", Process.myPid(), Process.myUid()) == 0) && (isSdCardMounted()); }
From source file:com.brainasylum.andruid.UniqueIdentifierManager.java
private static boolean canReadExternalStorage(Context context) { return (context.checkPermission("android.permission.READ_EXTERNAL_STORAGE", Process.myPid(), Process.myUid()) == 0) && ((isSdCardMountedReadOnly()) || (isSdCardMounted())); }
From source file:Main.java
public static boolean check(Context context, String... premissions) { try {/*from w w w . j a v a2 s .com*/ if (null == context) throw new RuntimeException("Context is null."); for (int i = 0; i < premissions.length; i++) { Integer check = context.checkPermission(premissions[i], Binder.getCallingPid(), Binder.getCallingUid()); if (check == -1) { return false; } } return true; } catch (Exception e) { Log.e(TAG, e.getMessage(), e); return false; } }
From source file:com.facebook.stetho.server.SecureHttpRequestHandler.java
private static void enforcePermission(Context context, LocalSocket peer) throws IOException, PeerAuthorizationException { Credentials credentials = peer.getPeerCredentials(); int uid = credentials.getUid(); int pid = credentials.getPid(); if (LogUtil.isLoggable(Log.VERBOSE)) { LogUtil.v("Got request from uid=%d, pid=%d", uid, pid); }/*from w ww. j av a 2s.c om*/ String requiredPermission = Manifest.permission.DUMP; int checkResult = context.checkPermission(requiredPermission, pid, uid); if (checkResult != PackageManager.PERMISSION_GRANTED) { throw new PeerAuthorizationException( "Peer pid=" + pid + ", uid=" + uid + " does not have " + requiredPermission); } }
From source file:org.nativescript.widgets.image.Cache.java
/** * Get the external app cache directory. * * @param context The context to use/*from www. jav a2 s . com*/ * @return The external cache dir */ @TargetApi(VERSION_CODES.FROYO) public static File getExternalCacheDir(Context context) { if (Utils.hasFroyo()) { if (Utils.hasKitKat() || context.checkPermission(Manifest.permission.WRITE_EXTERNAL_STORAGE, android.os.Process.myPid(), android.os.Process.myUid()) == PackageManager.PERMISSION_GRANTED) { return context.getExternalCacheDir(); } return null; } // Before Froyo we need to construct the external cache dir ourselves final String cacheDir = "/Android/data/" + context.getPackageName() + "/cache/"; return new File(Environment.getExternalStorageDirectory().getPath() + cacheDir); }
From source file:com.nostra13.universalimageloader.sample.ui.activity.HomeActivity.java
/** * Determine whether <em>you</em> have been granted a particular permission. * * @param permission The name of the permission being checked. * * @return {@link android.content.pm.PackageManager#PERMISSION_GRANTED} if you have the * permission, or {@link android.content.pm.PackageManager#PERMISSION_DENIED} if not. * * @see android.content.pm.PackageManager#checkPermission(String, String) */// ww w . j a va 2 s. c om public static int checkSelfPermission(@NonNull Context context, @NonNull String permission) { if (permission == null) { throw new IllegalArgumentException("permission is null"); } return context.checkPermission(permission, android.os.Process.myPid(), android.os.Process.myUid()); }