簡體   English   中英

無論狀態如何,Google Awareness API中的HeadphoneFence.unplugged都會觸發

[英]HeadphoneFence.unplugged in the Google Awareness API fires regardless of the state

我正在使用Nexus 5X手機並嘗試使用Google Awareness API HeadphoneFence.unplugged() https://developers.google.com/android/reference/com/google/android/gms/awareness/fence/HeadphoneFence

我發現,第一次添加圍欄時,它會觸發我的未決意圖,然后無論我插入或拔出耳機,它都將觸發,即使它只是為拔出插頭而觸發。

我的代碼不是很有趣,因為它直接來自指南。

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);
                                        }
                                    }
                                });

@Herman似乎的確是這樣。 它會在啟動應用程序時(注冊了圍欄/接收器時)以及在您插入/拔下耳機時為您提供耳機的狀態。

從某種程度上講,我認為這是有道理的,如果連接了耳機,則您沒有拔掉它們,因此它會觸發FenceState.FALSE,而當您拔下它們時,它將觸發FenceState.TRUE。 但是,您可以選擇在

switch (fenceState.getCurrentState()) {
                case FenceState.TRUE:
                    Log.i(TAG, "Fence > Headphones plugged out");
                    break;
                case FenceState.FALSE:
                    Log.i(TAG, "Fence > Headphones are NOT plugged out.");
                    break;
                case FenceState.UNKNOWN:
                    Log.i(TAG, "Fence > The headphone fence is in an unknown state.");
                    break;
            }

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM