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
| // 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; | |
| } | |
| } |
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
| // 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); |
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
| // 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) { |
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
| // 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 |
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
| 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, |
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
| // 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 = "" |
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
| // 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)); |
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
| // Event type: "tick" | |
| // Context rule is automatically executed once every minute | |
| console.log("Tick!") |
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
| // Logging a message | |
| console.log("This is a console message") |