Created
December 31, 2013 21:46
-
-
Save bonetechnologies/8202538 to your computer and use it in GitHub Desktop.
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
package com.urbanairship.javalibtest; | |
import com.urbanairship.api.client.APIClient; | |
import com.urbanairship.api.client.APIClientResponse; | |
import com.urbanairship.api.client.APIPushResponse; | |
import com.urbanairship.api.client.APIRequestException; | |
import com.urbanairship.api.push.model.DeviceTypeData; | |
import com.urbanairship.api.push.model.PushPayload; | |
import com.urbanairship.api.push.model.audience.Selectors; | |
import com.urbanairship.api.push.model.notification.Notifications; | |
import java.io.IOException; | |
public class Main { | |
public static void main(String[] args) throws IOException { | |
sendPush(); | |
} | |
public static void sendPush() throws IOException { | |
String appKey = "applicationKey"; | |
String appSecret = "applicationMasterSecret"; | |
// Build and configure an APIClient | |
APIClient apiClient = APIClient.newBuilder() | |
.setKey(appKey) | |
.setSecret(appSecret) | |
.build(); | |
// Setup a payload for the message you want to send | |
PushPayload payload = PushPayload.newBuilder() | |
.setAudience(Selectors.all()) | |
.setNotification(Notifications.alert("API v3")) | |
.setDeviceTypes(DeviceTypeData.all()) | |
.build(); | |
// Try/Catch for any issues, any non 200 response, or non library | |
// related exceptions | |
try { | |
APIClientResponse<APIPushResponse> response = apiClient.push(payload); | |
System.out.println(response); | |
} | |
catch (APIRequestException ex){ | |
ex.printStackTrace(); | |
} | |
catch (IOException e){ | |
e.printStackTrace(); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment