我一直在尝试使用Android版Places SDK,但是在尝试使用PlaceDetectionClient.getCurrentPlace()访问当前位置时遇到问题。我向清单文件添加了不受限制的API密钥,并在Google控制台中启用了Places SDK。我的代码在下面,并且在服务中:
try {
mPlaceDetectionClient.getCurrentPlace(null)
.addOnSuccessListener(new OnSuccessListener<PlaceLikelihoodBufferResponse>() {
@Override
public void onSuccess(PlaceLikelihoodBufferResponse likelyPlaces) {
if (likelyPlaces != null && likelyPlaces.getCount() > 0) {
int bestIndex = 0;
float bestLikelihood = likelyPlaces.get(0).getLikelihood();
for (int i = 1; i < likelyPlaces.getCount(); i++) {
if (likelyPlaces.get(i).getLikelihood() > bestLikelihood) {
bestIndex = i;
}
}
PlaceManager.setPlace(likelyPlaces.get(bestIndex).getPlace());
}
else {
Log.e(TAG, "place was null!");
}
likelyPlaces.release();
stopSelf();
}
}).addOnFailureListener(new OnFailureListener() {
@Override
public void onFailure(@NonNull Exception e) {
Log.e(TAG, "place failure!" + e);
stopSelf();
}
});
} catch (SecurityException se) {
Log.e(TAG, "SecurityException when getting place");
stopSelf();
}
我遇到的具体错误如下,每五秒钟重复一次,持续两分钟:
11-08 13:41:33.426 3398-3429/domain.temp.wearapp E/JavaBinder: !!! FAILED BINDER TRANSACTION !!! (parcel size = 284)
11-08 13:41:33.432 3398-3429/domain.temp.wearapp W/GmsClient: IGmsServiceBroker.getService failed
android.os.DeadObjectException: Transaction failed on small parcel; remote process probably died
at android.os.BinderProxy.transactNative(Native Method)
at android.os.BinderProxy.transact(Binder.java:748)
at com.google.android.gms.common.internal.IGmsServiceBroker$Stub$zza.getService(Unknown Source:13)
at com.google.android.gms.common.internal.BaseGmsClient.getRemoteService(Unknown Source:244)
at com.google.android.gms.common.api.internal.zabo.run(Unknown Source:8)
at android.os.Handler.handleCallback(Handler.java:789)
at android.os.Handler.dispatchMessage(Handler.java:98)
at android.os.Looper.loop(Looper.java:164)
at android.os.HandlerThread.run(HandlerThread.java:65)
两分钟后,它将停止尝试重试,并在onFailure调用中给出以下异常:
11-08 13:41:35.429 3398-3398/domain.temp.wearapp E/PlaceService: place failure!com.google.android.gms.common.api.ApiException: 8: INTERNAL_ERROR
我花了数小时试图通过在线搜索和调整各种方法(最初是IntentService)来解决此问题,但是没有任何运气。非常感谢您的帮助!