Android 权限异常,即使在清单中设置了权限
在我的清单中,我有:Android 权限异常,即使在清单中设置了权限,android,google-play-services,geofencing,android-geofence,Android,Google Play Services,Geofencing,Android Geofence,在我的清单中,我有: <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"/> 我怎样才能解决这个问题 我拥有 我使用的是安卓6 这是我的代码: public void addGeofencesButtonHandler(View view) { if (!mGoogleApiClient.isConnected()) { Toast.makeTe
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"/>
我怎样才能解决这个问题
我拥有
我使用的是安卓6
这是我的代码:
public void addGeofencesButtonHandler(View view) {
if (!mGoogleApiClient.isConnected()) {
Toast.makeText(this, getString(R.string.not_connected), Toast.LENGTH_SHORT).show();
return;
}
try {
LocationServices.GeofencingApi.addGeofences(
mGoogleApiClient,
// The GeofenceRequest object.
getGeofencingRequest(),
// A pending intent that that is reused when calling removeGeofences(). This
// pending intent is used to generate an intent when a matched geofence
// transition is observed.
getGeofencePendingIntent()
).setResultCallback(this); // Result processed in onResult().
} catch (SecurityException securityException) {
// Catch exception generated if the app does not use ACCESS_FINE_LOCATION permission.
logSecurityException(securityException);
}
}
在为API 23编译时,必须获得该许可
关于这一点,有一篇很好的博文:也许你在你的清单中把你的权限放在了一个错误的
元素中
,我在你的完整清单下面有权限,你使用的是6.0吗?是的,我使用的是6.0。请检查这个
public void addGeofencesButtonHandler(View view) {
if (!mGoogleApiClient.isConnected()) {
Toast.makeText(this, getString(R.string.not_connected), Toast.LENGTH_SHORT).show();
return;
}
try {
LocationServices.GeofencingApi.addGeofences(
mGoogleApiClient,
// The GeofenceRequest object.
getGeofencingRequest(),
// A pending intent that that is reused when calling removeGeofences(). This
// pending intent is used to generate an intent when a matched geofence
// transition is observed.
getGeofencePendingIntent()
).setResultCallback(this); // Result processed in onResult().
} catch (SecurityException securityException) {
// Catch exception generated if the app does not use ACCESS_FINE_LOCATION permission.
logSecurityException(securityException);
}
}