Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Awareness API Query for Fence State

I am trying to get fence state with the Awareness API. Here is the documentation about this. But... When using:

Awareness.FenceApi.queryFences

I can see its deprecated, and instead need to use:

Awareness.getFenceClient

Can anyone please give me an example how to get fence status with getFenceClient?

like image 544
Dim Avatar asked Jun 03 '18 12:06

Dim


1 Answers

Got it:

Awareness.getFenceClient(context).queryFences(FenceQueryRequest.forFences(Arrays.asList(key)))
            .addOnSuccessListener(new OnSuccessListener<FenceQueryResponse>() {

                @Override
                public void onSuccess(FenceQueryResponse fenceQueryResponse) {

                    FenceStateMap map = fenceQueryResponse.getFenceStateMap();

                    for (String fenceKey : map.getFenceKeys()) {
                        FenceState fenceState = map.getFenceState(fenceKey);
                        Log.i(TAG, "Fence " + fenceKey + ": "
                                + fenceState.getCurrentState()
                                + ", was="
                                + fenceState.getPreviousState());
                    }
                }
            })
            .addOnFailureListener(new OnFailureListener() {
                @Override
                public void onFailure(@NonNull Exception e) {

                    Log.d(TAG, "Failed: " + e);
                }
            });
like image 67
Dim Avatar answered Oct 21 '22 15:10

Dim