Please help me understand why my awareness fence that I have setup does not return a TRUE state for being "Still". I am running the app on my phone and I am "Still", and I have kept the phone "Still" for a while to make sure that their is no delay in the trigger.
Note: My fence is being successfully registered, so it can't be a problem with the api request etc. My broadcast receiver is never triggered as well.
The result of the code below is:
I/Awareness: Fence was successfully registered.
I/Awareness: Fence sitting_at_work: 0, was=0
Code:
AwarenessFence sittingFence = DetectedActivityFence.during(DetectedActivityFence.STILL);
Intent intent = new Intent(getContext(), activityReceiver.class);
intent.setAction(activityReceiver.ACTION_FENCE);
myPendingIntent = PendingIntent.getBroadcast(getContext(), 0, intent, PendingIntent.FLAG_UPDATE_CURRENT);
Awareness.getFenceClient(getContext()).updateFences(new FenceUpdateRequest.Builder()
.addFence(activityReceiver.KEY_SITTING_AT_WORK, sittingFence, myPendingIntent)
.build())
.addOnSuccessListener(new OnSuccessListener<Void>() {
@Override
public void onSuccess(Void aVoid) {
Log.i("Awareness", "Fence was successfully registered.");
Awareness.getFenceClient(getContext())
.queryFences(FenceQueryRequest.forFences(Arrays.asList(activityReceiver.KEY_SITTING_AT_WORK)))
.addOnSuccessListener(new OnSuccessListener<FenceQueryResponse>() {
@Override
public void onSuccess(FenceQueryResponse response) {
FenceStateMap map = response.getFenceStateMap();
for (String fenceKey : map.getFenceKeys()) {
FenceState fenceState = map.getFenceState(fenceKey);
Log.i("Awareness", "Fence " + fenceKey + ": "
+ fenceState.getCurrentState()
+ ", was="
+ fenceState.getPreviousState());
}
}
})
.addOnFailureListener(new OnFailureListener() {
@Override
public void onFailure(@NonNull Exception e) {
Log.e("Awareness", "Could not query fence: " + activityReceiver.KEY_SITTING_AT_WORK);
return;
}
});
}
})
.addOnFailureListener(new OnFailureListener() {
@Override
public void onFailure(@NonNull Exception e) {
Log.e("Awareness", "Fence could not be registered: " + e);
}
});
BroadcastReceiver onReceive:
if (TextUtils.equals(ACTION_FENCE, intent.getAction())) {
FenceState fenceState = FenceState.extract(intent);
Log.d("Awareness", "Detected fence action"); }