Example usage for android.app Activity shouldShowRequestPermissionRationale

List of usage examples for android.app Activity shouldShowRequestPermissionRationale

Introduction

In this page you can find the example usage for android.app Activity shouldShowRequestPermissionRationale.

Prototype

public boolean shouldShowRequestPermissionRationale(@NonNull String permission) 

Source Link

Document

Gets whether you should show UI with rationale for requesting a permission.

Usage

From source file:Main.java

public static boolean shouldShowRequestPermissionRationale(Activity context) {
    return context.shouldShowRequestPermissionRationale(Manifest.permission.ACCESS_COARSE_LOCATION);
}

From source file:Main.java

@TargetApi(value = Build.VERSION_CODES.M)
public static boolean hasNeverAskAgainPermission(Activity activity, List<String> permission) {
    for (String value : permission) {
        if (activity.checkSelfPermission(value) != PackageManager.PERMISSION_GRANTED
                && !activity.shouldShowRequestPermissionRationale(value)) {
            return true;
        }/*  ww w  . j a v a 2s  .  c  o  m*/
    }

    return false;
}

From source file:de.baumann.browser.helper.helper_main.java

public static void grantPermissionsLoc(final Activity from) {

    final SharedPreferences sharedPref = PreferenceManager.getDefaultSharedPreferences(from);

    if (android.os.Build.VERSION.SDK_INT >= 23) {

        if (sharedPref.getBoolean("perm_notShow", false)) {
            int hasACCESS_FINE_LOCATION = from.checkSelfPermission(Manifest.permission.ACCESS_FINE_LOCATION);
            if (hasACCESS_FINE_LOCATION != PackageManager.PERMISSION_GRANTED) {
                if (!from.shouldShowRequestPermissionRationale(Manifest.permission.ACCESS_FINE_LOCATION)) {
                    new AlertDialog.Builder(from).setTitle(R.string.app_permissions_title)
                            .setMessage(helper_main.textSpannable(from.getString(R.string.app_permissions)))
                            .setNeutralButton(R.string.toast_notAgain, new DialogInterface.OnClickListener() {
                                @Override
                                public void onClick(DialogInterface dialog, int which) {
                                    dialog.cancel();
                                    sharedPref.edit().putBoolean("perm_notShow", false).apply();
                                }/*from ww w  .j a v  a2  s  .  c om*/
                            }).setPositiveButton(from.getString(R.string.toast_yes),
                                    new DialogInterface.OnClickListener() {
                                        @Override
                                        public void onClick(DialogInterface dialog, int which) {
                                            if (android.os.Build.VERSION.SDK_INT >= 23)
                                                from.requestPermissions(
                                                        new String[] {
                                                                Manifest.permission.ACCESS_FINE_LOCATION },
                                                        REQUEST_CODE_ASK_PERMISSIONS_1);
                                        }
                                    })
                            .setNegativeButton(from.getString(R.string.toast_cancel), null).show();
                    return;
                }
                from.requestPermissions(new String[] { Manifest.permission.ACCESS_FINE_LOCATION },
                        REQUEST_CODE_ASK_PERMISSIONS_1);
            }
        }
    }
}

From source file:de.baumann.browser.helper.helper_main.java

public static void grantPermissionsStorage(final Activity from) {

    final SharedPreferences sharedPref = PreferenceManager.getDefaultSharedPreferences(from);

    if (android.os.Build.VERSION.SDK_INT >= 23) {
        if (sharedPref.getBoolean("perm_notShow", false)) {
            int hasWRITE_EXTERNAL_STORAGE = from
                    .checkSelfPermission(Manifest.permission.WRITE_EXTERNAL_STORAGE);
            if (hasWRITE_EXTERNAL_STORAGE != PackageManager.PERMISSION_GRANTED) {
                if (!from.shouldShowRequestPermissionRationale(Manifest.permission.WRITE_EXTERNAL_STORAGE)) {

                    new AlertDialog.Builder(from).setTitle(R.string.app_permissions_title)
                            .setMessage(helper_main.textSpannable(from.getString(R.string.app_permissions)))
                            .setNeutralButton(R.string.toast_notAgain, new DialogInterface.OnClickListener() {
                                @Override
                                public void onClick(DialogInterface dialog, int which) {
                                    dialog.cancel();
                                    sharedPref.edit().putBoolean("perm_notShow", false).apply();
                                }//from  www . j  ava 2 s  . c  o  m
                            }).setPositiveButton(from.getString(R.string.toast_yes),
                                    new DialogInterface.OnClickListener() {
                                        @Override
                                        public void onClick(DialogInterface dialog, int which) {
                                            if (android.os.Build.VERSION.SDK_INT >= 23)
                                                from.requestPermissions(
                                                        new String[] {
                                                                Manifest.permission.WRITE_EXTERNAL_STORAGE },
                                                        REQUEST_CODE_ASK_PERMISSIONS);
                                        }
                                    })
                            .setNegativeButton(from.getString(R.string.toast_cancel), null).show();
                    return;
                }
                from.requestPermissions(new String[] { Manifest.permission.WRITE_EXTERNAL_STORAGE },
                        REQUEST_CODE_ASK_PERMISSIONS);
            }
        }
    }
}

From source file:com.tbruyelle.rxpermissions.RxPermissions.java

@TargetApi(Build.VERSION_CODES.M)
private boolean shouldShowRequestPermissionRationale_(final Activity activity, final String... permissions) {
    for (String p : permissions) {
        if (!isGranted(p) && !activity.shouldShowRequestPermissionRationale(p)) {
            return false;
        }//from w  w  w.j  a  v  a2 s .c  o  m
    }
    return true;
}

From source file:com.codyy.rx.permissions.RxPermissions.java

@TargetApi(Build.VERSION_CODES.M)
private boolean shouldShowRequestPermissionRationaleImplementation(final Activity activity,
        final String... permissions) {
    for (String p : permissions) {
        if (!isGranted(p) && !activity.shouldShowRequestPermissionRationale(p)) {
            return false;
        }/*from   w  w  w.  j a v  a2 s.co  m*/
    }
    return true;
}

From source file:org.artoolkit.ar.samples.nftBook.CameraSurface.java

@SuppressWarnings("deprecation")
public CameraSurface(Context context) {
    super(context);

    Log.i(TAG, "CameraSurface(): ctor called");
    Activity activityRef = (Activity) context;

    try {/*w ww  .  j  ava2s  .  com*/
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
            if (PackageManager.PERMISSION_GRANTED != ContextCompat.checkSelfPermission(activityRef,
                    Manifest.permission.CAMERA)) {
                mustAskPermissionFirst = true;
                if (activityRef.shouldShowRequestPermissionRationale(Manifest.permission.CAMERA)) {
                    // Will drop in here if user denied permissions access camera before.
                    // Or no uses-permission CAMERA element is in the
                    // manifest file. Must explain to the end user why the app wants
                    // permissions to the camera devices.
                    Toast.makeText(activityRef.getApplicationContext(),
                            "App requires access to camera to be granted", Toast.LENGTH_SHORT).show();
                }
                // Request permission from the user to access the camera.
                Log.i(TAG, "CameraSurface(): must ask user for camera access permission");
                activityRef.requestPermissions(new String[] { Manifest.permission.CAMERA },
                        nftBookActivity.REQUEST_CAMERA_PERMISSION_RESULT);
                return;
            }
        }
    } catch (Exception ex) {
        Log.e(TAG, "CameraSurface(): exception caught, " + ex.getMessage());
        return;
    }

    SurfaceHolder holder = getHolder();
    holder.addCallback(this);
    holder.setType(SurfaceHolder.SURFACE_TYPE_PUSH_BUFFERS); // Deprecated in API level 11. Still required for API levels <= 10.
}

From source file:org.artoolkit.ar.samples.ARNativeES1.CameraSurface.java

@SuppressWarnings("deprecation")
public CameraSurface(Context context) {
    super(context);

    Log.i(TAG, "CameraSurface(): ctor called");
    Activity activityRef = (Activity) context;

    try {/*from   ww w . ja v  a 2s.  c om*/
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
            if (PackageManager.PERMISSION_GRANTED != ContextCompat.checkSelfPermission(activityRef,
                    Manifest.permission.CAMERA)) {
                mustAskPermissionFirst = true;
                if (activityRef.shouldShowRequestPermissionRationale(Manifest.permission.CAMERA)) {
                    // Will drop in here if user denied permissions access camera before.
                    // Or no uses-permission CAMERA element is in the
                    // manifest file. Must explain to the end user why the app wants
                    // permissions to the camera devices.
                    Toast.makeText(activityRef.getApplicationContext(),
                            "App requires access to camera to be granted", Toast.LENGTH_SHORT).show();
                }
                // Request permission from the user to access the camera.
                Log.i(TAG, "CameraSurface(): must ask user for camera access permission");
                activityRef.requestPermissions(new String[] { Manifest.permission.CAMERA },
                        ARNativeES1Activity.REQUEST_CAMERA_PERMISSION_RESULT);
                return;
            }
        }
    } catch (Exception ex) {
        Log.e(TAG, "CameraSurface(): exception caught, " + ex.getMessage());
        return;
    }

    SurfaceHolder holder = getHolder();
    holder.addCallback(this);
    holder.setType(SurfaceHolder.SURFACE_TYPE_PUSH_BUFFERS); // Deprecated in API level 11. Still required for API levels <= 10.
}

From source file:org.artoolkit.ar.samples.ARNativeOSG.CameraSurface.java

@SuppressWarnings("deprecation")
public CameraSurface(Context context) {
    super(context);

    Log.i(TAG, "CameraSurface(): ctor called");
    Activity activityRef = (Activity) context;

    try {/*  w w  w.j a va2s .c om*/
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
            if (PackageManager.PERMISSION_GRANTED != ContextCompat.checkSelfPermission(activityRef,
                    Manifest.permission.CAMERA)) {
                mustAskPermissionFirst = true;
                if (activityRef.shouldShowRequestPermissionRationale(Manifest.permission.CAMERA)) {
                    // Will drop in here if user denied permissions access camera before.
                    // Or no uses-permission CAMERA element is in the
                    // manifest file. Must explain to the end user why the app wants
                    // permissions to the camera devices.
                    Toast.makeText(activityRef.getApplicationContext(),
                            "App requires access to camera to be granted", Toast.LENGTH_SHORT).show();
                }
                // Request permission from the user to access the camera.
                Log.i(TAG, "CameraSurface(): must ask user for camera access permission");
                activityRef.requestPermissions(new String[] { Manifest.permission.CAMERA },
                        ARNativeOSGActivity.REQUEST_CAMERA_PERMISSION_RESULT);
                return;
            }
        }
    } catch (Exception ex) {
        Log.e(TAG, "CameraSurface(): exception caught, " + ex.getMessage());
        return;
    }

    SurfaceHolder holder = getHolder();
    holder.addCallback(this);
    holder.setType(SurfaceHolder.SURFACE_TYPE_PUSH_BUFFERS); // Deprecated in API level 11. Still required for API levels <= 10.
}

From source file:org.artoolkit.ar.samples.ARNative.CameraSurface.java

@SuppressWarnings("deprecation")
public CameraSurface(Context context) {
    super(context);

    Log.i(TAG, "CameraSurface(): ctor called");
    Activity activityRef = (Activity) context;

    try {/*from  w w w .  j a  v  a 2 s . co  m*/
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
            if (PackageManager.PERMISSION_GRANTED != ContextCompat.checkSelfPermission(activityRef,
                    Manifest.permission.CAMERA)) {
                mustAskPermissionFirst = true;
                if (activityRef.shouldShowRequestPermissionRationale(Manifest.permission.CAMERA)) {
                    // Will drop in here if user denied permissions access camera before.
                    // Or no uses-permission CAMERA element is in the
                    // manifest file. Must explain to the end user why the app wants
                    // permissions to the camera devices.
                    Toast.makeText(activityRef.getApplicationContext(),
                            "App requires access to camera to be granted", Toast.LENGTH_SHORT).show();
                }
                // Request permission from the user to access the camera.
                Log.i(TAG, "CameraSurface(): must ask user for camera access permission");
                activityRef.requestPermissions(new String[] { Manifest.permission.CAMERA },
                        ARNativeActivity.REQUEST_CAMERA_PERMISSION_RESULT);
                return;
            }
        }
    } catch (Exception ex) {
        Log.e(TAG, "CameraSurface(): exception caught, " + ex.getMessage());
        return;
    }

    SurfaceHolder holder = getHolder();
    holder.addCallback(this);
    holder.setType(SurfaceHolder.SURFACE_TYPE_PUSH_BUFFERS); // Deprecated in API level 11. Still required for API levels <= 10.
}