Awareness Fence API

时间:2017-02-26 14:36:52

标签: android google-awareness

我正在尝试为我正在使用的跟踪器注册Fence API以用于自动暂停/恢复功能。广播捕获DetectedActivityFence.stopping但是DetectedActivityFence.startingDetectedActivityFence.during没有来广播接收器,所以自动暂停正在工作,但不幸的是,简历。 我错过了什么吗?

注意:我尝试使用HeadphoneFence.pluggingInHeadphoneFence.unplugging围栏并且能够在同一个广播接收器中获取这两个事件。

将围栏注册为;

    AwarenessFence starting = DetectedActivityFence.starting(DetectedActivityFence.ON_BICYCLE);
    AwarenessFence during = DetectedActivityFence.during(DetectedActivityFence.ON_BICYCLE);
    AwarenessFence stopping = DetectedActivityFence.stopping(DetectedActivityFence.ON_BICYCLE);

   final FenceUpdateRequest.Builder fenceUpdateBuilder = new FenceUpdateRequest.Builder();
        for (AwarenessFence awarenessFence : fenceList) {
            fenceUpdateBuilder.addFence(fenceKey, awarenessFence, mPendingIntent);
        }


        googleApiClient.registerConnectionCallbacks(new GoogleApiClient.ConnectionCallbacks() {
            @Override
            public void onConnected(@Nullable Bundle bundle) {
                Awareness.FenceApi.updateFences(
                        googleApiClient, fenceUpdateBuilder.build())
                        .setResultCallback(new ResultCallback<Status>() {
                            @Override
                            public void onResult(@NonNull Status status) {
                                googleApiClient.disconnect();
                            }
                        });
            }

            @Override
            public void onConnectionSuspended(int i) {

            }
        });

我的广播

 @Override
    public void onReceive(Context context, Intent intent) {
        FenceState fenceState = FenceState.extract(intent);

        if (TextUtils.equals(fenceState.getFenceKey(), FENCE_CYCLING_ACTIVITY)) {
            switch (fenceState.getCurrentState()) {
                case FenceState.TRUE:

                    Intent serviceIntent = new Intent(context, ActivityRecordService.class);
                    serviceIntent.putExtra(ActivityRecordService.EXTRA_AWARENESS_INPUT, ActivityRecordService.AWARENESS_STARTED_CYCLING);
                    context.startService(serviceIntent);
                    break;

                case FenceState.FALSE:

                    Intent serviceIntent2 = new Intent(context, ActivityRecordService.class);
                    serviceIntent2.putExtra(ActivityRecordService.EXTRA_AWARENESS_INPUT, ActivityRecordService.AWARENESS_STOPPED_CYCLING);
                    context.startService(serviceIntent2);
                    break;
            }
        }
    }

0 个答案:

没有答案