在我的清单中我有:
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"/>
然而,当我运行我的应用程序并按下需要此权限的按钮时,我得到以下异常:
Geofence usage requires ACCESS_FINE_LOCATION permission
我该如何解决这个问题?
我在<manifest>
我使用的是Android 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);
}
}
答案 0 :(得分:1)
编译API 23时,您必须要求该权限。
Theres是一篇很好的博客文章:http://android-developers.blogspot.de/2015/09/google-play-services-81-and-android-60.html