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
// Creating a beacon region with name "Beacon", tag "beacon-tag" | |
BeaconProxy proxy = new BeaconProxy(); | |
proxy.createBeacon("Beacon", "B9407F30-F5F8-466E-AFF9-25556B57FE6D", 100, 1, new String[]{"beacon-tag"}, | |
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(); | |
Toast.makeText(getActivity(), result.getName(), Toast.LENGTH_SHORT).show(); | |
} |
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
// Unsubscribe from "office-chaione" tag to stop receiving events from beacon and geofence elements for that tag | |
List<String> tags = new ArrayList<String>("office-chaione"); | |
List<String> subscriptionTypes = Arrays.asList("beacon", "geofence"); | |
SubscriptionProxy proxy = new SubscriptionProxy(); | |
proxy.updateSubscriptions(SubscriptionOperation.REMOVE, tags, subscriptionTypes, new Callback<SubscriptionResponse>() { | |
@Override | |
public void onSuccess(SubscriptionResponse result) { | |
Toast.makeText(getActivity(), "Beacon and geofence subscriptions removed", Toast.LENGTH_SHORT).show(); | |
} | |
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
// Subscribe to "office-chaione" tag and start receiving events from beacon and geofence elements with that tag | |
List<String> tags = Arrays.asList("office-chaione"); | |
List<String> subscriptionTypes = Arrays.asList("beacon", "geofence"); | |
SubscriptionProxy proxy = new SubscriptionProxy(); | |
proxy.updateSubscriptions(SubscriptionOperation.ADD, tags, subscriptionTypes, new Callback<SubscriptionResponse>() { | |
@Override | |
public void onSuccess(SubscriptionResponse result) { | |
Toast.makeText(getActivity(), "Beacon and geofence subscriptions removed", Toast.LENGTH_SHORT).show(); | |
} | |
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); | |
// set custom payload provider | |
ContextHub.getInstance().setSensorPipelinePayloadProvider(this); | |
} |
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
// Deleting a vault item | |
final String id = "B89ECE55-9A3B-4998-AD58-2927F99802B7"; | |
VaultProxy<Person> proxy = new VaultProxy<Person>(); | |
proxy.deleteDocument(id, new Callback<Object>() { | |
@Override | |
public void onSuccess(Object result) { | |
Log.d(TAG, String.format("Successfully deleted item id %s", id)); | |
} | |
@Override |
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
// Updating a vault item with the first name "Darin" and adding the tag "employee" | |
// Update *replaces* a vault record with new contents so you must have a copy of the previous record if you want to make a change to a single value | |
person.setName("Darin"); | |
VaultProxy<Person> proxy = new VaultProxy<Person>(); | |
proxy.updateDocument(person, Person.class, "B89ECE55-9A3B-4998-AD58-2927F99802B7", new String[]{"kramerica", "employee"}, new VaultCallback<Person>() { | |
@Override | |
public void onSuccess(VaultDocument<Person> result) { | |
Log.d(TAG, result.getDataObject().toString()); | |
} |
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
// Get all vault documents with the tag "sample" and match "name = 'Cosmo Kramer'" | |
VaultProxy<Person> proxy = new VaultProxy<Person>(); | |
proxy.listDocuments("name", "Cosmo Kramer", new String[]{"sample"}, Person.class, new VaultListingCallback<Person>() { | |
@Override | |
public void onSuccess(VaultDocument<Person>[] result) { | |
for(VaultDocument<Person> document : result) {} | |
Log.d(TAG, document.getDataObject().toString()); | |
} | |
} |
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
// Getting a vault item with a specific ID | |
VaultProxy<Person> proxy = new VaultProxy<Person>(); | |
proxy.getDocument("41D8C25F-0464-41C5-A2E3-AAC234F240E4", Person.class, new VaultCallback<Person>() { | |
@Override | |
public void onSuccess(VaultDocument<Person> result) { | |
Log.d(TAG, result.getDataObject().toString()); | |
} | |
@Override | |
public void onFailure(Exception e) { |
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
// Get all vault documents with the tag "sample" and log the results | |
VaultProxy<Person> proxy = new VaultProxy<Person>(); | |
proxy.listDocuments(new String[]{"sample"}, Person.class, new VaultListingCallback<Person>() { | |
@Override | |
public void onSuccess(VaultDocument<Person>[] result) { | |
for(VaultDocument<Person> document : result) {} | |
Log.d(TAG, document.getDataObject().toString()); | |
} | |
} |
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
class Person implements Serializable { | |
String name; | |
String title; | |
ArrayList<String> nicknames; | |
int heightInInches; | |
int age; | |
public Person(String name, String title, ArrayList<String> nicknames, int heightInInches, int age) { | |
this.name = name; |