繁体   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