使用GPS提示的问题是Call requires permission which may be rejected by user: code should explicitly check to s

来源:互联网 发布:彩虹6号优化补丁 编辑:程序博客网 时间:2024/06/16 14:02

1.在使用GPS的时候提示Call requires permission which may be rejected by user: code should explicitly check to see if permission is available (with `checkPermission`) or explicitly handle a potential `SecurityException`more... (Ctrl+F1),这句话的意思是:调用需要的权限可能被用户拒绝,代码应该显示地检查权限是否可用,用checkpermission或者显示地处理一个潜在的SecurityException异常,这时候其实已经说明你的api使用的是23以上了,

2.我的解决办法是添加判断,代码如下:

if (ContextCompat.checkSelfPermission(this, android.Manifest.permission.ACCESS_FINE_LOCATION) == PackageManager.PERMISSION_GRANTED        || ContextCompat.checkSelfPermission(this, android.Manifest.permission.ACCESS_COARSE_LOCATION) == PackageManager.PERMISSION_GRANTED) 
{}

阅读全文
1 0