我使用的是Nexus 5X手機,並試圖從谷歌API意識HeadphoneFence.unplugged()https://developers.google.com/android/reference/com/google/android/gms/awareness/fence/HeadphoneFenceHeadphoneFence.unplugged在谷歌API意識,無論觸發狀態
我發現,它激發我的懸而未決的意圖時,首先添加柵欄,然後無論我插入還是拔下耳機,它甚至會啓動,只會引發拔火。
我的代碼不是那麼令人感興趣,因爲它是從指南中直接出來的。
Awareness.FenceApi.updateFences(
getGoogleApiClient(),
new FenceUpdateRequest.Builder()
.addFence(
"something",
HeadphoneFence.unplugging();,
createSendHeadphoneUnpluggedMessagePendingIntent(context))
.build())
.setResultCallback(new ResultCallback<Status>() {
@Override
public void onResult(@NonNull Status status) {
if(status.isSuccess()) {
Log.i(TAG, "Headphone unplugged fence was successfully registered.");
} else {
Log.e(TAG, "Headphone unplugged fence could not be registered: " + status);
}
}
});
您想要發佈完整的代碼嗎?我會嘗試複製它 – buddhabath
忘記標記您的答覆^^ – buddhabath
放入pastebin:http://pastebin.com/SYfuit10如果您需要更多信息,請告知我。 – Herman