Java/Kotlin Server SDK
∞ Installation
The Beams Java/Kotlin server SDK is available on Maven Central.
<dependencies>
<dependency>
<groupId>com.pusher</groupId>
<artifactId>push-notifications-server-java</artifactId>
<version>1.1.1</version>
</dependency>
</dependencies>
dependencies {
compile 'com.pusher:push-notifications-server-java:1.1.1'
}
You can download a version of the .jar
directly from Maven.
∞ Reference
∞ Class: PushNotifications
PushNotifications(instanceId, secretKey)
Construct a new Pusher Beams Client connected to your Beams instance.
∞ Arguments
- ∞ instanceIdString Required
-
The unique identifier for your Push notifications instance. This can be found in the dashboard under “Credentials”.
- ∞ secretKeyString Required
-
The secret key your server will use to access your Beams instance. This can be found in the dashboard under “Credentials”.
∞ Example
String instanceId = "YOUR_INSTANCE_ID_HERE";
String secretKey = "YOUR_SECRET_KEY_HERE";
PushNotifications beamsClient = new PushNotifications(instanceId, secretKey);
val instanceId = "YOUR_INSTANCE_ID_HERE"
val secretKey = "YOUR_SECRET_KEY_HERE"
val beamsClient = PushNotifications(instanceId, secretKey)
∞ .publishToInterests
Sends broadcast notifications to groups of subscribed devices using Device Interests
∞ Arguments
- ∞ interestsList<String> Required
-
List of interests to send the push notification to, ranging from 1 to 100 per publish request. See Interests.
- ∞ publishRequestMap<String, Map> Required
-
Map containing the body of the push notification publish request. See publish API reference.
∞ Returns
String that contains publishId
: See publish API reference
∞ Example
List<String> interests = Arrays.asList("donuts", "pizza");
Map<String, Map> publishRequest = new HashMap();
Map<String, String> apsAlert = new HashMap();
apsAlert.put("title", "hello");
apsAlert.put("body", "Hello world");
Map<String, Map> alert = new HashMap();
alert.put("alert", apsAlert);
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);
Map<String, String> webNotification = new HashMap();
webNotification.put("title", "hello");
webNotification.put("body", "Hello world");
Map<String, Map> web = new HashMap();
web.put("notification", webNotification);
publishRequest.put("web", web);
beamsClient.publishToInterests(interests, publishRequest);
val interests = listOf("donuts", "pizza")
val publishRequest = hashMapOf(
"apns" to hashMapOf("aps" to hashMapOf("alert" to hashMapOf("title" to "hello", "body" to "Hello world"))),
"fcm" to hashMapOf("notification" to hashMapOf("title" to "hello", "body" to "Hello world")),
"web" to hashMapOf("notification" to hashMapOf("title" to "hello", "body" to "Hello world"))
)
beamsClient.publishToInterests(interests, publishRequest)
∞ .publishToUsers
Securely send notifications to individual users of your application using Authenticated Users
∞ Arguments
- ∞ userIdsList<String> Min length=1, Max length=1000 Required
-
List of ids of users to send the push notification to, ranging from 1 to 1000 per publish request. See Authenticated Users
- ∞ publishRequestMap<String, Map> Required
-
Map containing the body of the push notification publish request. See publish API reference.
∞ Returns
String that contains publishId
: See publish API reference
∞ Example
List<String> users = Arrays.asList("user-001", "user-002");
Map<String, Map> publishRequest = new HashMap();
Map<String, String> apsAlert = new Hashmap();
apsAlert.put("title", "hello");
apsAlert.put("body", "Hello world");
Map<String, Map> alert = new HashMap();
alert.put("alert", apsAlert);
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);
Map<String, String> webNotification = new HashMap();
webNotification.put("title", "hello");
webNotification.put("body", "Hello world");
Map<String, Map> web = new HashMap();
web.put("notification", webNotification);
publishRequest.put("web", web);
beamsClient.publishToUsers(users, publishRequest);
val users = listOf("user-001", "user-002")
val publishRequest = hashMapOf(
"apns" to hashMapOf("aps" to hashMapOf("alert" to "hashMapOf("title" to "hello", "body" to "Hello world"))),
"fcm" to hashMapOf("notification" to hashMapOf("title" to "hello", "body" to "Hello world")),
"web" to hashMapOf("notification" to hashMapOf("title" to "hello", "body" to "Hello world"))
)
beamsClient.publishToUsers(users, publishRequest)
∞ .generateToken
Generate a Beams auth token to allow a user to associate their device with their user id. The token is valid for 24 hours.
∞ Arguments
- ∞ userIDString Required
-
Id of the user you would like to generate a Beams auth token for.
∞ Returns
- ∞ beamsTokenMap<String, Any>
-
Beams Token for the given user
∞ Example
String userId = "user-001";
Map<String, Object> token = beamsClient.generateToken(userId);
val userId = "user-001"
val token = beamsClient.generateToken(userId)