private static int sendSegmentPush(String text, String targetOS, int ttl, APIClient apiClient) throws IOException { Alert<String> alert = new Alert<String>(text); // remove this line if you just want to send it to all registered // devices alert.setTargetOS(targetOS); // do not keep the push more than 2 minutes if device is not // available alert.setTTL(ttl); // push to all devices that didn't open the app since // last day (last 24 hours). List<Alert.BehaviorSegment> segments = new ArrayList<Alert.BehaviorSegment>(); Alert.BehaviorSegment segment = new Alert.BehaviorSegment( Alert.Behavior.last_app_open, new Alert.BehaviorSegment.Interval(Alert.IntervalUnit.day, 1)); // we are interested on devices that did NOT open the app, so we want to exclude devices // that did match the above interval segment.setExclude(true); segments.add(segment); alert.setBehaviorSegments(segments); return apiClient.publish(alert); }
private static int sendPush(String text, String targetOS, int ttl, APIClient apiClient) throws IOException { Alert<String> alert = new Alert<String>(text); // remove this line if you just want to send it to all registered // devices alert.setTargetOS(targetOS); // do not keep the push more than 2 minutes if device is not // available alert.setTTL(ttl); // Uncomment this line if you prefer to implicitly create tags // if there are tags passed on this alert that do not // exist on the project // alert.setImplicitTagCreation(true); List<String> tags = new ArrayList<String>(); // send push to all registered devices tags.add(Alert.ALL_PUSH_TAG); alert.setTags(tags); // make this push 'normal' priority, meaning the gateway (GCM, APNS) // could delay it if device is sleeping alert.setNotificationPriority(Alert.Priority.normal); return apiClient.publish(alert); }
private static Alert<String> buildScheduledPush( String text, Date scheduledAt, String targetOS, int ttl) { Alert<String> alert = new Alert<String>(text); // remove this line if you just want to send it to all registered // devices alert.setTargetOS(targetOS); // do not keep the push more than 2 minutes if device is not // available alert.setTTL(ttl); List<String> tags = new ArrayList<String>(); // send push to all registered devices tags.add("test-channel"); tags.add("dev-channel"); alert.setTags(tags, Alert.TAG_MATCH_OP_AND); // make this push 'normal' priority, meaning the gateway (GCM, APNS) // could delay it if device is sleeping alert.setNotificationPriority(Alert.Priority.normal); alert.setScheduledAt(scheduledAt); return alert; }