Pusher Beams Java Server SDK
Installation
The compiled library is available in two ways:
Maven
The push-notifications-server-java is available in Maven Central.
<dependencies>
<dependency>
<groupId>com.pusher</groupId>
<artifactId>push-notifications-server-java</artifactId>
<version>1.1.1</version>
</dependency>
</dependencies>
Gradle
dependencies {
compile 'com.pusher:push-notifications-server-java:1.1.1'
}
Download
You can download a version of the .jar
directly from Maven.
Usage
Configuring the SDK for Your Instance
Use your instance id and secret (you can get these from the dashboard) to create a Beams PushNotifications instance:
Java
String instanceId = "8f9a6e22-2483-49aa-8552-125f1a4c5781";
String secretKey = "C54D42FB7CD2D408DDB22D7A0166F1D";
PushNotifications pushNotifications = new PushNotifications(instanceId, secretKey);
Kotlin
val instanceId = "8f9a6e22-2483-49aa-8552-125f1a4c5781"
val secretKey = "C54D42FB7CD2D408DDB22D7A0166F1D"
val pn = PushNotifications(instanceId, secretKey)
Publishing a Notification
Once you have created your PushNotifications instance you can publish a push notification to your registered & subscribed devices:
Java
List<String> interests = Arrays.asList("donuts", "pizza");
Map<String, Map> publishRequest = new HashMap();
Map<String, String> alert = new HashMap();
alert.put("alert", "hi");
Map<String, Map> aps = new HashMap();
aps.put("aps", alert);
publishRequest.put("apns", aps);
Map<String, String> fcmNotification = new HashMap();
fcmNotification.put("title", "hello");
fcmNotification.put("body", "Hello world");
Map<String, Map> fcm = new HashMap();
fcm.put("notification", fcmNotification);
publishRequest.put("fcm", fcm);
pushNotifications.publishToInterests(interests, publishRequest);
Kotlin
val interests = listOf("donuts", "pizza")
val publishRequest = hashMapOf(
"apns" to hashMapOf("aps" to hashMapOf("alert" to "hi")),
"fcm" to hashMapOf("notification" to hashMapOf("title" to "hello", "body" to "Hello world"))
)
pn.publishToInterests(interests, publishRequest)