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:Main.java
/** * Checks if the application is in the background (i.e behind another application's Activity). * * @param context {@link Context}//from ww w. java 2 s . co m * @return true if another application is above this one. */ public static boolean isApplicationBroughtToBackground(final Context context) { if (context.checkCallingOrSelfPermission(Manifest.permission.GET_TASKS) == PackageManager.PERMISSION_DENIED) return false; ActivityManager am = (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE); List<RunningTaskInfo> tasks = am.getRunningTasks(1); if (!tasks.isEmpty()) { ComponentName topActivity = tasks.get(0).topActivity; if (!topActivity.getPackageName().equals(context.getPackageName()) && !topActivity.getPackageName().equals("com.google.android.voicesearch")) { return true; } } return false; }
From source file:org.thaliproject.p2p.btconnectorlib.utils.CommonUtils.java
/** * Checks whether the given permission is granted (by the user) for the given activity. * * @param permission The permission to check. * @param activity The activity.// w w w. j a v a 2 s .c o m * @return True, if granted. False otherwise. */ @TargetApi(23) public static boolean isPermissionGranted(String permission, Activity activity) { int permissionCheck = PackageManager.PERMISSION_DENIED; if (activity != null) { permissionCheck = ContextCompat.checkSelfPermission(activity, permission); Log.i(TAG, "isPermissionGranted: " + permission + ": " + permissionCheck); } else { throw new NullPointerException("The given activity is null"); } return (permissionCheck == PackageManager.PERMISSION_GRANTED); }
From source file:com.google.samples.apps.iosched.util.PermissionsUtils.java
/** * Determine if any permission is in the denied state. *//*from w w w .jav a 2s. c o m*/ public static boolean anyPermissionDenied(Context context, String[] permissions) { for (String permission : permissions) { if (ContextCompat.checkSelfPermission(context, permission) == PackageManager.PERMISSION_DENIED) { return true; } } return false; }
From source file:com.netease.hearttouch.htimagepicker.core.util.permission.PermissionsChecker.java
private boolean lacksPermission(String permission) { return ContextCompat.checkSelfPermission(mContext, permission) == PackageManager.PERMISSION_DENIED; }
From source file:com.smoothsync.smoothsetup.utils.Denied.java
public Denied(Context context, Iterable<String> permissions) { super(new Sieved<>(p -> ContextCompat.checkSelfPermission(context, p) == PackageManager.PERMISSION_DENIED, permissions));//www . j a v a 2 s .co m }
From source file:com.canelmas.let.Let.java
/** * Check permission results and execute the {@link com.canelmas.let.AskPermission} annotated, * runtime permission required method afterwards if each permission required is granted. * * @param source/*from w ww .ja va 2 s .c om*/ * @param requestCode The request code received in {@link android.app.Activity#onRequestPermissionsResult(int, String[], int[])} * or {@link android.app.Fragment#onRequestPermissionsResult(int, String[], int[])} * @param permissions Permission list received in {@link android.app.Activity#onRequestPermissionsResult(int, String[], int[])} * or {@link android.app.Fragment#onRequestPermissionsResult(int, String[], int[])} * @param grantResults Result list received in {@link android.app.Activity#onRequestPermissionsResult(int, String[], int[])} * or {@link android.app.Fragment#onRequestPermissionsResult(int, String[], int[])} */ public static void handle(Object source, int requestCode, String[] permissions, int[] grantResults) { final DelayedTasks.Task delayedTask = DelayedTasks.get(requestCode); if (null != delayedTask) { final List<DeniedPermission> deniedPermissions = new ArrayList<>(); final LetContext letContext = new LetContext(source); for (int k = 0; k < permissions.length; k++) { boolean denied = grantResults[k] == PackageManager.PERMISSION_DENIED; if (denied) { boolean shouldShowRationale = ActivityCompat .shouldShowRequestPermissionRationale(letContext.getActivity(), permissions[k]); boolean neverAskAgain = !shouldShowRationale; deniedPermissions.add(new DeniedPermission(permissions[k], neverAskAgain)); Logger.log("\t" + permissions[k] + " denied" + (neverAskAgain ? " with Never Ask Again checked." : "")); } } if (deniedPermissions.isEmpty()) { try { Logger.log("<<< Required permissions granted"); delayedTask.execute(); } catch (Exception e) { throw new LetException("Delayed Execution Failed!", e); } } else { RuntimePermissionListener listener = RuntimePermissionListener.class.isInstance(source) ? (RuntimePermissionListener) source : null; if (null != listener) { Logger.log("<<< should handle denied permissions"); listener.onPermissionDenied(deniedPermissions); } } } else { Logger.log("No delayed task to execute."); } }
From source file:com.zj.image.ActivityMain.java
@Override public void onClick(final View v) { if (PermissionChecker.checkSelfPermission(this, Manifest.permission.CAMERA) == PackageManager.PERMISSION_DENIED) { ActivityCompat.requestPermissions(this, new String[] { Manifest.permission.CAMERA }, v.getId()); } else {/*from w w w . j ava 2s.c o m*/ startActivity(v.getId()); } }
From source file:jp.co.cyberagent.android.gpuimage.sample.activity.ActivityMain.java
@Override public void onClick(final View v) { if (PermissionChecker.checkSelfPermission(this, Manifest.permission.CAMERA) == PackageManager.PERMISSION_DENIED) { ActivityCompat.requestPermissions(this, new String[] { Manifest.permission.CAMERA }, v.getId()); } else if (PermissionChecker.checkSelfPermission(this, Manifest.permission.WRITE_EXTERNAL_STORAGE) == PackageManager.PERMISSION_DENIED) { ActivityCompat.requestPermissions(this, new String[] { Manifest.permission.WRITE_EXTERNAL_STORAGE }, v.getId());/*from ww w .ja v a 2 s . c o m*/ } else { startActivity(v.getId()); } }
From source file:com.hplasplas.cam_capture.managers.FileSystemManager.java
private static File getDirectory(boolean needPrivate) { File dir;/*from w ww .java 2 s . com*/ if (needPrivate) { dir = ThisApplication.getInstance().getExternalFilesDir(PICTURE_FOLDER_NAME); } else { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M && ContextCompat.checkSelfPermission(ThisApplication.getMainContext(), Manifest.permission.READ_EXTERNAL_STORAGE) == PackageManager.PERMISSION_DENIED) { dir = ThisApplication.getInstance().getExternalFilesDir(PICTURE_FOLDER_NAME); } else { dir = new File(Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_PICTURES), PICTURE_FOLDER_NAME); } } if (dir != null && !dir.exists() && !dir.mkdir()) { throw new IllegalStateException("Dir create error"); } return dir; }
From source file:com.unovo.frame.core.permissions.PermissionsAction.java
@Override protected boolean interrupt() { boolean interrupt = super.interrupt(); if (requestCode == 0) { }//from w w w . ja v a2s . c o m // SDK23 else if (Build.VERSION.SDK_INT < 23) { } // ?? else if (PackageManager.PERMISSION_GRANTED == ContextCompat.checkSelfPermission(getContext(), permission)) { Logger.i("???, permission = %s", permission); } // ??? else if (PackageManager.PERMISSION_DENIED == ContextCompat.checkSelfPermission(getContext(), permission)) { interrupt = true; Logger.i("PERMISSION_DENIED permission = %s", permission); doInterrupt(); } return interrupt; }