Skip to content

Instantly share code, notes, and snippets.

View CHLibrarian's full-sized avatar

ContextHub CHLibrarian

View GitHub Profile
@CHLibrarian
CHLibrarian / application-services-sending-custom-data-android.java
Created November 11, 2014 17:55
ContextHub Application Services Sending Custom Data (Android)
// A class representing the custom data to send
public class MyCustomData {
String appName;
int version;
public MyCustomData(String appName, int version) {
this.appName = appName;
this.version = version;
}
}
@CHLibrarian
CHLibrarian / application-services-receiving-push-android.java
Created November 11, 2014 17:46
ContextHub Application Services Receiving Push (Android)
// Implement the PushPayloadHandler interface
public class NotificationHandler implements PushPayloadHandler {
private static final int NOTIFICATION_ID = 1;
private static final String KEY_MESSAGE = "message";
@Override
public void handlePushPayload(Context context, Bundle bundle) {
if(bundle.containsKey(KEY_MESSAGE)) {
showNotification(context, bundle);
@CHLibrarian
CHLibrarian / application-service-sending-to-tags-android.java
Created November 11, 2014 17:44
ContextHub Application Services Sending To Tags (Android)
// Send a push notification to all devices with tags "tag1" and "tag2"
// Note: If a device has both "tag1" and "tag2", they will receive the same notification twice
String tag1 = "tag1";
String tag2 = "tag2";
SimplePushNotification notification = new SimplePushNotification("Test push notification message");
notification.getTags().add(tag1);
notification.getTags().add(tag2);
PushNotificationProxy proxy = new PushNotificationProxy();
proxy.sendSimplePushNotification(notification, new Callback<Object>() {
@Override
@CHLibrarian
CHLibrarian / application-services-sending-to-alias-android.java
Created November 11, 2014 17:41
ContextHub Application Services Sending To Alias (Android)
// Send a push notification to 2 devices, with aliases "Andy's Moto X" and "Chris' Nexus 5"
String alias1 = "Andy's Moto X";
String alias2 = "Chris' Nexus 5";
SimplePushNotification notification = new SimplePushNotification("Test push notification message");
notification.getAliases().add(alias1);
notification.getAliases().add(alias2);
PushNotificationProxy proxy = new PushNotificationProxy();
proxy.sendSimplePushNotification(notification, new Callback<Object>() {
@Override
public void onSuccess(Object result) {
@CHLibrarian
CHLibrarian / application-services-sending-to-device-android.java
Last active August 29, 2015 14:09
ContextHub Application Services Sending To Device (Android)
// Send a push to 2 devices with IDs defined below
// Note: All device IDs are UUIDs, if a deviceID is not a valid UUID, then it is not a valid device ID
String deviceId1 = "20984403-690A-4098-8557-73B763F1DFFB";
String deviceId2 = "151E57AF-7E87-400F-A1E0-63C9E7811376";
SimplePushNotification notification = new SimplePushNotification("Test push notification message");
notification.getDeviceIds().add(deviceId1);
notification.getDeviceIds().add(deviceId2);
PushNotificationProxy proxy = new PushNotificationProxy();
proxy.sendSimplePushNotification(notification, new Callback<Object>() {
@Override
@CHLibrarian
CHLibrarian / application-services-register-push-android.java
Last active August 29, 2015 14:09
ContextHub Application Services Register Push (Android)
public class NotifyMeApp extends Application {
@Override
public void onCreate() {
super.onCreate();
// Register with ContextHub
ContextHub.init(this, "YOUR-APP-ID-HERE");
/* Initialize push service with your GCM sender id, the device alias,
@CHLibrarian
CHLibrarian / context-rule-push-background.js
Last active August 29, 2015 14:06
ContextHub Context Rule Push Background Gist
// Sending background pushes via different identifiers
var token = "71962e3cbc7dfa91e8bec21b532b69c211a55453a1407299bb78f931c7e8f7ec"
var deviceId = "BC903204-51C1-4DF6-92E8-F5A5DE00E26E"
var alias = "Jeff's iPhone 5"
var arrayOfTags = new Array()
arrayOfTags.push("device-tag")
var data = { "payload": {"age": "25", "height": "6.25"} }
var sound = ""
@CHLibrarian
CHLibrarian / context-rule-push.js
Last active August 29, 2015 14:06
ContextHub Context Rule Push Gist
// Sending simple notification to all devices with the 'active' tag
push.deliver( JSON.stringify({tags: ["active"], alert: "Hello World."}));
// Sending a silent background notification
var data = { "commuter": "group_location_refresh" };
var devices = [ "5048A9B5-2089-4AD6-AAE4-25E7837385AC", "2e074d0b18b7b190" ]
var payload = { "device_ids" : devices, "priority" : 10, "sound" : "", "content_available" : 1, "data" : data };
push.deliver(JSON.stringify(payload));
@CHLibrarian
CHLibrarian / context-rule-tick.js
Created September 5, 2014 03:20
ContextHub Context Rule Tick Gist
// Event type: "tick"
// Context rule is automatically executed once every minute
console.log("Tick!")
@CHLibrarian
CHLibrarian / context-rule-console.js
Created September 5, 2014 02:57
ContextHub Context Rule Console Gist
// Logging a message
console.log("This is a console message")