当我试图获取GPS坐标时,它会抛出异常甚至我在清单文件中拥有ACCESS_COARSE_LOCATION and ACCESS_FINE_LOCATION
权限,并且我在运行时请求了权限。
Manifest File:
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-feature android:name="android.hardware.location.gps" />
运行时权限检查:
if (ActivityCompat.checkSelfPermission(mContext, Manifest.permission.ACCESS_FINE_LOCATION) !=
PackageManager.PERMISSION_GRANTED &&
ActivityCompat.checkSelfPermission(mContext, Manifest.permission.ACCESS_COARSE_LOCATION) !=
PackageManager.PERMISSION_GRANTED)
我获得例外的地方:
locationManager.requestLocationUpdates(
LocationManager.GPS_PROVIDER, MIN_TIME_BW_UPDATES, MIN_DISTANCE_CHANGE_FOR_UPDATES,this);
locationManager.isProviderEnabled(LocationManager.GPS_PROVIDER)
返回true
编辑:
这是我得到的例外情况:
java.lang.SecurityException: "gps" location provider requires ACCESS_FINE_LOCATION permission.