本文整理汇总了Java中android.support.v4.app.ActivityCompat.shouldShowRequestPermissionRationale方法的典型用法代码示例。如果您正苦于以下问题:Java ActivityCompat.shouldShowRequestPermissionRationale方法的具体用法?Java ActivityCompat.shouldShowRequestPermissionRationale怎么用?Java ActivityCompat.shouldShowRequestPermissionRationale使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类android.support.v4.app.ActivityCompat
的用法示例。
在下文中一共展示了ActivityCompat.shouldShowRequestPermissionRationale方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: requestCameraPermission
import android.support.v4.app.ActivityCompat; //导入方法依赖的package包/类
private void requestCameraPermission() {
Log.w(TAG, "Write External permission is not granted. Requesting permission");
final String[] permissions = new String[]{Manifest.permission.CAMERA};
if (ActivityCompat.shouldShowRequestPermissionRationale(this, Manifest.permission.CAMERA)) {
ActivityCompat.requestPermissions(this, permissions, Constants.PERMISSION_REQUEST_CAMERA);
} else {
if (!isPermissionRequested(Constants.PREF_CAMERA_REQUESTED)) {
ActivityCompat.requestPermissions(this, permissions, Constants.PERMISSION_REQUEST_CAMERA);
setPermissionRequested(Constants.PREF_CAMERA_REQUESTED);
} else {
Snackbar snackbar = Snackbar.make(mainLayout, R.string.msg_no_camera_permission,
Snackbar.LENGTH_INDEFINITE);
snackbar.setAction(R.string.ok, new View.OnClickListener() {
@Override
public void onClick(View view) {
openAppSettings();
}
});
snackbar.show();
}
}
}
示例2: checkLocationPermission
import android.support.v4.app.ActivityCompat; //导入方法依赖的package包/类
public boolean checkLocationPermission(){
if (ContextCompat.checkSelfPermission(this,
android.Manifest.permission.ACCESS_FINE_LOCATION)
!= PackageManager.PERMISSION_GRANTED) {
if (ActivityCompat.shouldShowRequestPermissionRationale(this,
android.Manifest.permission.ACCESS_FINE_LOCATION)) {
ActivityCompat.requestPermissions(this,
new String[]{android.Manifest.permission.ACCESS_FINE_LOCATION},
MY_PERMISSIONS_REQUEST_LOCATION);
} else {
ActivityCompat.requestPermissions(this,
new String[]{android.Manifest.permission.ACCESS_FINE_LOCATION},
MY_PERMISSIONS_REQUEST_LOCATION);
}
return false;
} else {
return true;
}
}
示例3: checkPermission
import android.support.v4.app.ActivityCompat; //导入方法依赖的package包/类
private void checkPermission() {
int deniedIndex = checkSelfPermissions(permissions);
if (deniedIndex != -1) {
if (ActivityCompat.shouldShowRequestPermissionRationale(this, permissions[deniedIndex])) {
if (TextUtils.isEmpty(rationalMessage)) {
requestPermission();
} else {
showRationalDialog();
}
} else {
requestPermission();
}
} else {
sendGrantMessage();
}
}
示例4: requestPermissions
import android.support.v4.app.ActivityCompat; //导入方法依赖的package包/类
private void requestPermissions() {
boolean shouldProvideRationale =
ActivityCompat.shouldShowRequestPermissionRationale(this,
android.Manifest.permission.ACCESS_COARSE_LOCATION);
// Provide an additional rationale to the user. This would happen if the user denied the
// request previously, but didn't check the "Don't ask again" checkbox.
if (shouldProvideRationale) {
Log.i(TAG, "Displaying permission rationale to provide additional context.");
} else {
Log.i(TAG, "Requesting permission");
// Request permission. It's possible this can be auto answered if device policy
// sets the permission in a given state or the user denied the permission
// previously and checked "Never ask again".
startLocationPermissionRequest();
}
}
示例5: shouldShowRequestPermissionRationale
import android.support.v4.app.ActivityCompat; //导入方法依赖的package包/类
private static boolean shouldShowRequestPermissionRationale(@NonNull Object object,
@NonNull String perm) {
if (object instanceof Activity) {
return ActivityCompat.shouldShowRequestPermissionRationale((Activity) object, perm);
} else if (object instanceof Fragment) {
return ((Fragment) object).shouldShowRequestPermissionRationale(perm);
} else if (object instanceof android.app.Fragment) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
return ((android.app.Fragment) object).shouldShowRequestPermissionRationale(perm);
} else {
throw new IllegalArgumentException(
"Target SDK needs to be greater than 23 if caller is android.app.Fragment");
}
} else {
throw new IllegalArgumentException("Object was neither an Activity nor a Fragment.");
}
}
示例6: askForPermission
import android.support.v4.app.ActivityCompat; //导入方法依赖的package包/类
private void askForPermission(String permission, Integer requestCode) {
if (ContextCompat.checkSelfPermission(getActivity(), permission) != PackageManager.PERMISSION_GRANTED) {
// Should we show an explanation?
if (ActivityCompat.shouldShowRequestPermissionRationale(getActivity(), permission)) {
//This is called if user has denied the permission before
//In this case I am just asking the permission again
ActivityCompat.requestPermissions(getActivity(), new String[]{permission}, requestCode);
} else {
ActivityCompat.requestPermissions(getActivity(), new String[]{permission}, requestCode);
}
} else {
}
}
示例7: requestPermissions
import android.support.v4.app.ActivityCompat; //导入方法依赖的package包/类
private void requestPermissions(Activity activity, String[] permissions) {
ArrayList<String> permissionsToExplain = new ArrayList<>();
for (String permission : permissions) {
if (ActivityCompat.shouldShowRequestPermissionRationale(activity, permission)) {
permissionsToExplain.add(permission);
}
}
if (listener != null && permissionsToExplain.size() > 0) {
// The developer should show an explanation to the user asynchronously
listener.onExplanationNeeded(permissionsToExplain);
}
ActivityCompat.requestPermissions(activity, permissions, REQUEST_PERMISSIONS_CODE);
}
示例8: shouldShowRequestPermissionRationale
import android.support.v4.app.ActivityCompat; //导入方法依赖的package包/类
/**
* 是否有权限需要说明提示
*/
private static boolean shouldShowRequestPermissionRationale(final Context context, final String... deniedPermissions) {
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.M) return false;
boolean rationale;
for (String permission : deniedPermissions) {
rationale = ActivityCompat.shouldShowRequestPermissionRationale((Activity) context, permission);
if (rationale) return true;
}
return false;
}
示例9: requestStoragePermission
import android.support.v4.app.ActivityCompat; //导入方法依赖的package包/类
private void requestStoragePermission() {
if (ActivityCompat.shouldShowRequestPermissionRationale(this, Manifest.permission.WRITE_EXTERNAL_STORAGE)) {
new PermissionDeclarationDialogFragment().show(getSupportFragmentManager(), FRAGMENT_DIALOG);
} else {
ActivityCompat.requestPermissions(this, new String[]{Manifest.permission.WRITE_EXTERNAL_STORAGE}, REQUEST_STORAGE_PERMISSION);
}
}
示例10: shouldShowRequestPermissionRationale
import android.support.v4.app.ActivityCompat; //导入方法依赖的package包/类
/**
* 用户拒绝的权限
*/
private static boolean shouldShowRequestPermissionRationale(final Activity activity, String[] permissions) {
StringBuilder msgbff = new StringBuilder();
if (permissions.length < 1) {
return false;
}
// Verify that each required permission has been granted, otherwise return false.
for (String p : permissions) {
//如果app之前请求过该权限,被用户拒绝, 这个方法就会返回true.
//如果用户之前拒绝权限的时候勾选了对话框中”Don’t ask again”的选项,那么这个方法会返回false.
//如果设备策略禁止应用拥有这条权限, 这个方法也返回false.
if (ActivityCompat.shouldShowRequestPermissionRationale(activity, p)) {
msgbff.append(getPermissionCN(p)).append("\n");
}
}
String msg = msgbff.toString();
if (msg.length() > 0) {
final DialogMsgBox dialogMsgBox = new DialogMsgBox(activity);
msg ="请授予以下权限:\n"+msg;
dialogMsgBox.show("权限请求", msg);
dialogMsgBox.but_ok.setText("去设置");
dialogMsgBox.but_ok.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
dialogMsgBox.dismiss();
AndroidUtils.showInstalledAppDetails(activity, activity.getPackageName());
}
});
return true;
}
return false;
}
示例11: requestPermission
import android.support.v4.app.ActivityCompat; //导入方法依赖的package包/类
/**
* Make request permission
* @param activity Activity
*/
private static void requestPermission(Activity activity) {
if (ActivityCompat.shouldShowRequestPermissionRationale(activity, android.Manifest.permission.WRITE_EXTERNAL_STORAGE)) {
Log.d(TAG, "Write External Storage permission allows us to do store shortcuts data. Please allow this permission in App Settings.");
} else {
ActivityCompat.requestPermissions(activity, new String[]{android.Manifest.permission.WRITE_EXTERNAL_STORAGE}, 111);
Log.d(TAG, "Write External Storage permission allows us to do store shortcuts data.");
}
}
示例12: findDeniedPermissions
import android.support.v4.app.ActivityCompat; //导入方法依赖的package包/类
/**
* 获取权限集中需要申请权限的列表
*
* @param permissions
* @return
* @since 2.5.0
*/
private static List<String> findDeniedPermissions(String[] permissions) {
List<String> needRequestPermissonList = new ArrayList<String>();
for (String perm : permissions) {
if (ContextCompat.checkSelfPermission(context, perm) != PackageManager.PERMISSION_GRANTED) {
needRequestPermissonList.add(perm);
} else if (ActivityCompat.shouldShowRequestPermissionRationale(context, perm)) {
needRequestPermissonList.add(perm);
}
}
return needRequestPermissonList;
}
示例13: requestPermission
import android.support.v4.app.ActivityCompat; //导入方法依赖的package包/类
private void requestPermission() {
if (ActivityCompat.shouldShowRequestPermissionRationale(CustomDictionaryActivity.this, android.Manifest.permission.WRITE_EXTERNAL_STORAGE)) {
} else {
ActivityCompat.requestPermissions(CustomDictionaryActivity.this, new String[]{android.Manifest.permission.WRITE_EXTERNAL_STORAGE}, PERMISSION_REQUEST_CODE);
}
}
示例14: askForLocationPermission
import android.support.v4.app.ActivityCompat; //导入方法依赖的package包/类
public static void askForLocationPermission(Activity thisActivity, int requestCode) {
if (ContextCompat.checkSelfPermission(thisActivity,
Manifest.permission.READ_CONTACTS)
!= PackageManager.PERMISSION_GRANTED) {
// Should we show an explanation?
if (ActivityCompat.shouldShowRequestPermissionRationale(thisActivity,
Manifest.permission.ACCESS_FINE_LOCATION)) {
// Show an explanation to the user *asynchronously* -- don't block
// this thread waiting for the user's response! After the user
// sees the explanation, try again to request the permission.
// we force to allow this permission
ActivityCompat.requestPermissions(thisActivity,
new String[]{Manifest.permission.ACCESS_FINE_LOCATION},
requestCode);
} else {
// No explanation needed, we can request the permission.
ActivityCompat.requestPermissions(thisActivity,
new String[]{Manifest.permission.ACCESS_FINE_LOCATION},
requestCode);
// MY_PERMISSIONS_REQUEST_READ_CONTACTS is an
// app-defined int constant. The callback method gets the
// result of the request.
}
}
}
示例15: checkAndRequestPermission
import android.support.v4.app.ActivityCompat; //导入方法依赖的package包/类
public void checkAndRequestPermission(String permission, int result) {
int permissionGranted = getPackageManager().checkPermission(permission, getPackageName());
Log.i("[Permission] " + permission + " is " + (permissionGranted == PackageManager.PERMISSION_GRANTED ? "granted" : "denied"));
if (permissionGranted != PackageManager.PERMISSION_GRANTED) {
if (LinphonePreferences.instance().firstTimeAskingForPermission(permission) || ActivityCompat.shouldShowRequestPermissionRationale(this, permission)) {
Log.i("[Permission] Asking for " + permission);
ActivityCompat.requestPermissions(this, new String[]{permission}, result);
}
}
}