shouldShowRequestPermissionRationale 权限

shouldShowRequestPermissionRationale 1,在允许询问时返回true ; 2,在权限通过 或者权限被拒绝并且禁止询问时返回false 但是有一个例外,就是重来没有询问过的时候,也是返回的false 所以单纯的使用shouldShowRequestPermissionRationale去做什么判断,是没用的,只能在请求权限回调后再使用。 Google的原意是: 1,没有申请过权限,申请就是了,所以返回false; 2,申请了用户拒绝了,那你就要提示用户了,所以返回true; 3,用户选择了拒绝并且不再提示,那你也不要申请了,也不要提示用户了,所以返回false; 4,已经允许了,不需要申请也不需要提示,所以返回false

  • 3
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
Android获取位置权限需要以下步骤: 1.在AndroidManifest.xml文件中添加权限: ``` <uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" /> <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" /> ``` 2.在Activity中请求权限: ``` if (ContextCompat.checkSelfPermission(this, Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED) { // Permission is not granted if (ActivityCompat.shouldShowRequestPermissionRationale(this, 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. } else { // No explanation needed; request the permission ActivityCompat.requestPermissions(this, new String[]{Manifest.permission.ACCESS_FINE_LOCATION}, MY_PERMISSIONS_REQUEST_LOCATION); } } else { // Permission has already been granted } ``` 3.在回调函数onRequestPermissionsResult()中处理权限请求结果: ``` @Override public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions, @NonNull int[] grantResults) { if (requestCode == MY_PERMISSIONS_REQUEST_LOCATION) { // If request is cancelled, the result arrays are empty. if (grantResults.length > 0 && grantResults[0] == PackageManager.PERMISSION_GRANTED) { // permission was granted, yay! Do the // location-related task you need to do. } else { // permission denied, boo! Disable the // functionality that depends on this permission. } return; } // other 'case' lines to check for other // permissions this app might request } ``` 以上就是Android获取位置权限的方法。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值