Java Code Examples for android.app.Activity#shouldShowRequestPermissionRationale()

The following examples show how to use android.app.Activity#shouldShowRequestPermissionRationale() . 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: Utility.java    From XCallRecording-xposed with GNU General Public License v3.0 9 votes vote down vote up
static boolean checkStoragePermission(Activity activity, int requestCode) {
	if (Build.VERSION.SDK_INT <= Build.VERSION_CODES.LOLLIPOP_MR1) {
		// no need to check
		return true;
	}
	final String permission = Manifest.permission.WRITE_EXTERNAL_STORAGE;
	if (PackageManager.PERMISSION_GRANTED != activity.checkSelfPermission(permission)) {
		if (!activity.shouldShowRequestPermissionRationale(permission)) {
			activity.requestPermissions(new String[] {permission}, requestCode);
		} else {
			showToast(activity, R.string.warning_storage_permission);
		}
		return false;
	} else {
		return true;
	}
}
 
Example 2
Source File: LaunchService.java    From Xndroid with GNU General Public License v3.0 6 votes vote down vote up
@TargetApi(M)
static private void getPermission(String[] permissions, Activity activity) {
    if(Build.VERSION.SDK_INT>=23) {
        ArrayList<String> preToDo = new ArrayList<>();
        boolean tip = false;
        for (String pre : permissions) {
            if (activity.checkSelfPermission(pre) != PackageManager.PERMISSION_GRANTED) {
                preToDo.add(pre);
                if (activity.shouldShowRequestPermissionRationale(pre)) {
                    tip = true;
                }
            }
        }
        if (preToDo.size() == 0)
            return;
        if (tip)
            showToast(sContext.getString(R.string.permissions_need));
        activity.requestPermissions(preToDo.toArray(new String[preToDo.size()]), 0);
    }
}
 
Example 3
Source File: PermissionUtils.java    From XXPermissions with Apache License 2.0 6 votes vote down vote up
/**
     * 检查某个权限是否被永久拒绝
     *
     * @param activity              Activity对象
     * @param permission            请求的权限
     */
    private static boolean checkSinglePermissionPermanentDenied(Activity activity, String permission) {

//        // 安装权限和浮窗权限不算,本身申请方式和危险权限申请方式不同,因为没有永久拒绝的选项,所以这里返回false
//        if (Permission.REQUEST_INSTALL_PACKAGES.equals(permission) || Permission.SYSTEM_ALERT_WINDOW.equals(permission)) {
//            return false;
//        }

        // 检测8.0的两个新权限
        if (Permission.ANSWER_PHONE_CALLS.equals(permission) || Permission.READ_PHONE_NUMBERS.equals(permission)) {

            // 检查当前的安卓版本是否符合要求
            if (!isOverOreo()) {
                return false;
            }
        }

        if (isOverMarshmallow()) {
            if (activity.checkSelfPermission(permission) == PackageManager.PERMISSION_DENIED  &&
                    !activity.shouldShowRequestPermissionRationale(permission)) {
                return true;
            }
        }
        return false;
    }
 
Example 4
Source File: ActivityWindowAndroid.java    From 365browser with Apache License 2.0 6 votes vote down vote up
@Override
public boolean canRequestPermission(String permission) {
    if (Build.VERSION.SDK_INT < Build.VERSION_CODES.M) return false;

    Activity activity = getActivity().get();
    if (activity == null) return false;

    if (isPermissionRevokedByPolicy(permission)) {
        return false;
    }

    if (activity.shouldShowRequestPermissionRationale(permission)) {
        return true;
    }

    // Check whether we have ever asked for this permission by checking whether we saved
    // a preference associated with it before.
    String permissionQueriedKey = getHasRequestedPermissionKey(permission);
    SharedPreferences prefs = ContextUtils.getAppSharedPreferences();
    if (!prefs.getBoolean(permissionQueriedKey, false)) return true;

    return false;
}
 
Example 5
Source File: RxPermissions.java    From AndroidProjects with MIT License 5 votes vote down vote up
@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;
        }
    }
    return true;
}
 
Example 6
Source File: PermissionHelper.java    From justaline-android with Apache License 2.0 5 votes vote down vote up
/**
 * Determine if user has already been asked these permissions and denied us the ability to
 * ask again. If true, send them to system to grant required permissions.
 *
 * @param activity reference to activity we are checking
 * @return true if we cannot ask for the necessary permissions
 */
private static boolean shouldSendToSystemPrefsForRequiredPermissions(Activity activity) {
    int numTimesAsked = getSharedPreferences(activity)
            .getInt(PREF_NUM_TIMES_ASKED_REQUIRED_PERMISSIONS, 0);
    if (numTimesAsked > 1) {
        for (String permission : REQUIRED_PERMISSIONS) {
            if (ContextCompat.checkSelfPermission(activity, permission)
                    == PackageManager.PERMISSION_DENIED &&
                    !activity.shouldShowRequestPermissionRationale(permission)) {
                return true;
            }
        }
    }
    return false;
}
 
Example 7
Source File: PermissionFineLocation.java    From geopaparazzi with GNU General Public License v3.0 5 votes vote down vote up
@Override
public void requestPermission(final Activity activity) {
    if (canAskPermission) {
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
            if (activity.checkSelfPermission(
                    Manifest.permission.ACCESS_FINE_LOCATION) !=
                    PackageManager.PERMISSION_GRANTED) {

                if (activity.shouldShowRequestPermissionRationale(
                        Manifest.permission.ACCESS_FINE_LOCATION)) {
                    AlertDialog.Builder builder =
                            new AlertDialog.Builder(activity);
                    builder.setMessage(activity.getString(R.string.permissions_location));
                    builder.setPositiveButton(android.R.string.ok,
                            new DialogInterface.OnClickListener() {
                                @Override
                                public void onClick(DialogInterface dialog, int which) {
                                    activity.requestPermissions(new String[]{
                                                    Manifest.permission.ACCESS_FINE_LOCATION},
                                            FINE_LOCATION_PERMISSION_REQUESTCODE);
                                }
                            }
                    );
                    // display the dialog
                    builder.create().show();
                } else {
                    // request permission
                    activity.requestPermissions(
                            new String[]{Manifest.permission.ACCESS_FINE_LOCATION},
                            FINE_LOCATION_PERMISSION_REQUESTCODE);
                }
            }
        }
    }
}
 
Example 8
Source File: RxPermissions.java    From RxPermissions with Apache License 2.0 5 votes vote down vote up
@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;
        }
    }
    return true;
}
 
Example 9
Source File: PermUtil.java    From PixImagePicker with Apache License 2.0 5 votes vote down vote up
@RequiresApi(api = Build.VERSION_CODES.M)
private static boolean addPermission(List<String> permissionsList, String permission, Activity ac) {
    if (ac.checkSelfPermission(permission) != PackageManager.PERMISSION_GRANTED) {
        permissionsList.add(permission);
        // Check for Rationale Option
        return ac.shouldShowRequestPermissionRationale(permission);
    }
    return true;
}
 
Example 10
Source File: RxPermissions.java    From GankGirl with GNU Lesser General Public License v2.1 5 votes vote down vote up
@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;
        }
    }
    return true;
}
 
Example 11
Source File: MusicFinderPlugin.java    From Flute-Music-Player with Apache License 2.0 4 votes vote down vote up
private boolean shouldShowRequestPermissionRationale(Activity activity, String permission) {
  if (Build.VERSION.SDK_INT >= 23) {
    return activity.shouldShowRequestPermissionRationale(permission);
  }
  return false;
}
 
Example 12
Source File: ActivityCompatApi23.java    From letv with Apache License 2.0 4 votes vote down vote up
public static boolean shouldShowRequestPermissionRationale(Activity activity, String permission) {
    return activity.shouldShowRequestPermissionRationale(permission);
}
 
Example 13
Source File: PermissionUtil.java    From StatusSaver-for-Whatsapp with Apache License 2.0 4 votes vote down vote up
public static boolean shouldShowRational(Activity activity, String permission) {
    if (useRunTimePermissions()) {
        return activity.shouldShowRequestPermissionRationale(permission);
    }
    return false;
}
 
Example 14
Source File: Nammu.java    From MusicPlayer with GNU General Public License v3.0 4 votes vote down vote up
public static boolean shouldShowRequestPermissionRationale(Activity activity, String permissions) {
    return activity.shouldShowRequestPermissionRationale(permissions);
}
 
Example 15
Source File: Nammu.java    From Muzesto with GNU General Public License v3.0 4 votes vote down vote up
@TargetApi(Build.VERSION_CODES.M)
public static boolean shouldShowRequestPermissionRationale(Activity activity, String permissions) {
    return activity.shouldShowRequestPermissionRationale(permissions);
}
 
Example 16
Source File: M_Util.java    From AsteroidOSSync with GNU General Public License v3.0 4 votes vote down vote up
public static boolean shouldShowRequestPermissionRationale(Activity context) {
    return context.shouldShowRequestPermissionRationale(Manifest.permission.ACCESS_COARSE_LOCATION);
}
 
Example 17
Source File: PermissionGetAccounts.java    From geopaparazzi with GNU General Public License v3.0 4 votes vote down vote up
@Override
public void requestPermission(final Activity activity) {
    if (canAskPermission) {
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
            if (activity.checkSelfPermission(
                    Manifest.permission.GET_ACCOUNTS) !=
                    PackageManager.PERMISSION_GRANTED) {

                if (canAskPermission) {
                    if (activity.shouldShowRequestPermissionRationale(
                            Manifest.permission.GET_ACCOUNTS)) {
                        AlertDialog.Builder builder =
                                new AlertDialog.Builder(activity);
                        builder.setMessage(activity.getString(R.string.permissions_accounts));
                        builder.setPositiveButton(android.R.string.ok,
                                new DialogInterface.OnClickListener() {
                                    @Override
                                    public void onClick(DialogInterface dialog, int which) {
                                        if (canAskPermission) {
                                            activity.requestPermissions(new String[]{
                                                            Manifest.permission.GET_ACCOUNTS},
                                                    GET_ACCOUNTS_PERMISSION_REQUESTCODE);
                                        }
                                    }
                                }
                        );
                        // display the dialog
                        builder.create().show();
                    } else {
                        // request permission
                        if (canAskPermission) {
                            activity.requestPermissions(
                                    new String[]{Manifest.permission.GET_ACCOUNTS},
                                    GET_ACCOUNTS_PERMISSION_REQUESTCODE);
                        }
                    }
                }
            }
        }
    }
}
 
Example 18
Source File: PermissionWriteStorage.java    From geopaparazzi with GNU General Public License v3.0 4 votes vote down vote up
@Override
public void requestPermission(final Activity activity) {
    if (canAskPermission) {
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
            if (activity.checkSelfPermission(
                    Manifest.permission.WRITE_EXTERNAL_STORAGE) !=
                    PackageManager.PERMISSION_GRANTED) {

                if (canAskPermission) {
                    if (activity.shouldShowRequestPermissionRationale(
                            Manifest.permission.WRITE_EXTERNAL_STORAGE)) {
                        AlertDialog.Builder builder =
                                new AlertDialog.Builder(activity);
                        builder.setMessage(activity.getString(R.string.permissions_write_disk));
                        builder.setPositiveButton(android.R.string.ok,
                                new DialogInterface.OnClickListener() {
                                    @Override
                                    public void onClick(DialogInterface dialog, int which) {
                                        if (canAskPermission) {
                                            activity.requestPermissions(new String[]{
                                                            Manifest.permission.WRITE_EXTERNAL_STORAGE},
                                                    WRITE_EXTERNAL_STORAGE_PERMISSION_REQUESTCODE);
                                        }
                                    }
                                }
                        );
                        // display the dialog
                        builder.create().show();
                    } else {
                        // request permission
                        if (canAskPermission) {
                            activity.requestPermissions(
                                    new String[]{Manifest.permission.WRITE_EXTERNAL_STORAGE},
                                    WRITE_EXTERNAL_STORAGE_PERMISSION_REQUESTCODE);
                        }
                    }
                }
            }
        }
    }
}
 
Example 19
Source File: PermissionForegroundService.java    From geopaparazzi with GNU General Public License v3.0 4 votes vote down vote up
@Override
public void requestPermission(final Activity activity) {
    if (canAskPermission) {
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
            if (activity.checkSelfPermission(
                    Manifest.permission.FOREGROUND_SERVICE) !=
                    PackageManager.PERMISSION_GRANTED) {

                if (canAskPermission) {
                    if (activity.shouldShowRequestPermissionRationale(
                            Manifest.permission.FOREGROUND_SERVICE)) {
                        AlertDialog.Builder builder =
                                new AlertDialog.Builder(activity);
                        builder.setMessage(activity.getString(R.string.permissions_foreground_service));
                        builder.setPositiveButton(android.R.string.ok,
                                new DialogInterface.OnClickListener() {
                                    @Override
                                    public void onClick(DialogInterface dialog, int which) {
                                        if (canAskPermission) {
                                            if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.P) {
                                                activity.requestPermissions(new String[]{
                                                                Manifest.permission.FOREGROUND_SERVICE},
                                                        FOREGROUND_SERVICE_PERMISSION_REQUESTCODE);
                                            }
                                        }
                                    }
                                }
                        );
                        // display the dialog
                        builder.create().show();
                    } else {
                        // request permission
                        if (canAskPermission) {
                            if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.P) {
                                activity.requestPermissions(
                                        new String[]{Manifest.permission.FOREGROUND_SERVICE},
                                        FOREGROUND_SERVICE_PERMISSION_REQUESTCODE);
                            }
                        }
                    }
                }
            }
        }
    }
}
 
Example 20
Source File: PermissionSendSms.java    From geopaparazzi with GNU General Public License v3.0 4 votes vote down vote up
@Override
public void requestPermission(final Activity activity) {
    if (canAskPermission) {
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
            if (activity.checkSelfPermission(
                    Manifest.permission.SEND_SMS) !=
                    PackageManager.PERMISSION_GRANTED) {

                if (canAskPermission) {
                    if (activity.shouldShowRequestPermissionRationale(
                            Manifest.permission.SEND_SMS)) {
                        AlertDialog.Builder builder =
                                new AlertDialog.Builder(activity);
                        builder.setMessage(activity.getString(R.string.permissions_send_sms));
                        builder.setPositiveButton(android.R.string.ok,
                                new DialogInterface.OnClickListener() {
                                    @Override
                                    public void onClick(DialogInterface dialog, int which) {
                                        if (canAskPermission) {
                                            activity.requestPermissions(new String[]{
                                                            Manifest.permission.SEND_SMS},
                                                    SENDSMS_PERMISSION_REQUESTCODE);
                                        }
                                    }
                                }
                        );
                        // display the dialog
                        builder.create().show();
                    } else {
                        // request permission
                        if (canAskPermission) {
                            activity.requestPermissions(
                                    new String[]{Manifest.permission.SEND_SMS},
                                    SENDSMS_PERMISSION_REQUESTCODE);
                        }
                    }
                }
            }
        }
    }
}