Skip to content

Instantly share code, notes, and snippets.

View CHLibrarian's full-sized avatar

ContextHub CHLibrarian

View GitHub Profile
@CHLibrarian
CHLibrarian / element-services-subscription-add-android.java
Last active August 29, 2015 14:10
ContextHub Element Services Subscription Add (Android)
// Subscribing to a tag
// We want to subscribe to tags "my-tag- 1" and "my-tag-2" to be notified when beacons, geofences, or vault records with that tag are created, updated, or deleted
SubscriptionProxy proxy = new SubscriptionProxy();
List<String> tagList = Arrays.asList("my-tag-1", "my-tag-2");
List<String> subscriptionTypes = Arrays.asList("beacon", "geofence", "vault");
proxy.updateSubscriptions(SubscriptionOperation.ADD, tagList, subscriptionTypes, new Callback<SubscriptionResponse>() {
@Override
public void onSuccess(SubscriptionResponse result) {
Toast.makeText(getActivity(), ("Beacon, geofence, and vault subscriptions added", Toast.LENGTH_SHORT).show();
}
@CHLibrarian
CHLibrarian / element-services-geofence-delete-android.java
Created November 24, 2014 17:18
ContextHub Element Services Geofence Delete (Android)
final long id = 1000;
GeofenceProxy proxy = new GeofenceProxy();
proxy.deleteGeofence(id, new Callback<Object>() {
@Override
public void onSuccess(Object result) {
// If you do not have push properly set up, you need to explicitly call synchronize on LocationService so it will stop generating events for this geofence
LocationService.getInstance().synchronize();
Log.d(TAG, String.format("Successfully deleted geofence id %s", id));
}
@CHLibrarian
CHLibrarian / element-services-geofence-update-android.java
Created November 24, 2014 17:10
ContextHub Element Services Geofence Update (Android)
// Updating a geofence with the name "Geofence 2" and adding the tag "office"
// In order to update a geofence, you need to pass in a valid geofence object
geofence.setName("Geofence 2");
geofence.getTags().add("office");
GeofenceProxy proxy = new GeofenceProxy();
proxy.updateGeofence(geofence.getId(), geofence, new Callback<Geofence> {
@Override
public void onSuccess(Geofence result) {
// If you do not have push properly set up, you need to explicitly call synchronize on LocationService so it will generate events for this geofence
LocationService.getInstance().synchronize();
@CHLibrarian
CHLibrarian / element-services-geofence-retreive-id-android.java
Created November 24, 2014 17:08
ContextHub Element Services Geofence Retrieve ID (Android)
// Getting a geofence with a specific ID
GeofenceProxy proxy = new GeofenceProxy();
proxy.getGeofence(1000, new Callback<Geofence> {
@Override
public void onSuccess(Geofence result) {
Log.d(TAG, geofence.toString());
}
@Override
public void onFailure(Exception e) {
@CHLibrarian
CHLibrarian / element-services-geofence-retrieve-tags-android.java
Created November 24, 2014 17:04
ContextHub Element Services Geofence Retrieve Tags (Android)
// Getting the first 10 geofences with the tag "geofence-tag" near our location in 2000 meter radius
GeofenceProxy proxy = new GeofenceProxy();
proxy.listGeofences(29.763638f, -95.461874f, 2000, 10, new String[]{"geofence-tag"},
new Callback<List<Geofence>> {
@Override
public void onSuccess(List<Geofence> result) {
for(Geofence geofence : result) {
Log.d(TAG, geofence.toString());
}
}
@CHLibrarian
CHLibrarian / element-services-geofences-create-android.java
Created November 24, 2014 17:03
ContextHub Element Services Geofence Create (Android)
// Creating a geofence with name "Geofence", lat/lng of ChaiOne, tag "geofence-tag", radius 250 meters
GeofenceProxy proxy = new GeofenceProxy();
proxy.createGeofence("Geofence", 29.763638f, -95.461874f, 250, new String[]{"geofence-tag"},
new Callback<Geofence> {
@Override
public void onSuccess(Geofence result) {
// If you do not have push properly set up, you need to explicitly call synchronize on LocationService so it will generate events for this geofence
LocationService.getInstance().synchronize();
Toast.makeText(getActivity(), "Created geofence: " + result.getName(), Toast.LENGTH_SHORT).show();
}
@CHLibrarian
CHLibrarian / element-services-beacon-delete-android.java
Created November 24, 2014 17:00
ContextHub Element Services Beacon Delete (Android)
final String id = "B89ECE55-9A3B-4998-AD58-2927F99802B7";
BeaconProxy proxy = new BeaconProxy();
proxy.deleteBeacon(id, new Callback<Object>() {
@Override
public void onSuccess(Object result) {
// If you do not have push properly set up, you need to explicitly call synchronize on ProximityService so it will stop generating events for this device
ProximityService.getInstance().synchronize();
Log.d(TAG, String.format("Successfully deleted beacon id %s", id));
}
@CHLibrarian
CHLibrarian / element-services-beacon-update-android.java
Created November 24, 2014 16:59
ContextHub Element Services Beacon Update (Android)
// Updating a beacon with the name "Beacon 2" and adding the tag "park"
// In order to update a beacon, you need to pass in a valid beacon object
beacon.setName("Beacon 2");
beacon.getTags().add("park");
BeaconProxy proxy = new BeaconProxy();
proxy.updateBeacon(beacon.getId(), beacon, new Callback<Beacon> {
@Override
public void onSuccess(Beacon result) {
// If you do not have push properly set up, you need to explicitly call synchronize on ProximityService so it will generate events for this device
ProximityService.getInstance().synchronize();
@CHLibrarian
CHLibrarian / element-services-beacon-retrieve-id-android.java
Created November 24, 2014 16:58
ContextHub Element Services Beacon Retrieve ID (Android)
// Getting a beacon with a specific ID
BeaconProxy proxy = new BeaconProxy();
proxy.getBeacon(1000, new Callback<Beacon> {
@Override
public void onSuccess(Beacon result) {
Log.d(TAG, beacon.toString());
}
@Override
public void onFailure(Exception e) {
@CHLibrarian
CHLibrarian / element-services-beacon-retrieve-tags-android.java
Created November 24, 2014 16:57
ContextHub Element Services Beacon Retrieve Tags (Android)
// Getting beacons with the tag "beacon-tag"
BeaconProxy proxy = new BeaconProxy();
proxy.listBeacons(20, new String[]{"beacon-tag"}, new Callback<List<Beacon>> {
@Override
public void onSuccess(List<Beacon> result) {
for(Beacon beacon : result) {
Log.d(TAG, beacon.toString());
}
}