Created
November 24, 2014 20:35
-
-
Save CHLibrarian/c95bbcf56e9888bd5ac3 to your computer and use it in GitHub Desktop.
ContextHub Event Services Listener (Android)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@Override | |
public void onResume() { | |
super.onResume(); | |
// start listening to events | |
ContextHub.getInstance().addSensorPipelineListener(this); | |
} | |
@Override | |
public void onPause() { | |
super.onPause(); | |
// stop listening to events | |
ContextHub.getInstance().removeSensorPipelineListener(this); | |
} | |
@Override | |
public void onEventReceived(final SensorPipelineEvent event) { | |
if(event.getName().startsWith("geofence_")) { | |
// called on background thread, so use a Runnable to perform work on UI thread | |
getActivity().runOnUiThread(new Runnable() { | |
@Override | |
public void run() { | |
Toast.makeText(getActivity(), event.getName(), Toast.LENGTH_SHORT).show(); | |
} | |
}); | |
} | |
} | |
@Override | |
public boolean shouldPostEvent(SensorPipelineEvent event) { | |
// return true to allow events to post, false to prevent them from posting | |
return true; | |
} | |
@Override | |
public void onBeforeEventPosted(SensorPipelineEvent event) { | |
// add any extra details to the event before it is posted | |
} | |
@Override | |
public void onEventPosted(SensorPipelineEvent event) { | |
// handle an event after it has been posted to ContextHub | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment