A library to easily send notifications over Firebase Cloud Messaging (FCM). The library was built with the purpose of making the process of sending messages as simple and modular as posible.
FCM has had a total makeover for the new "REST v1 API". I have decided not to include backwards compatibility in Pushraven.
If you wish to use the (simpler) legacy API see Legacy Instructions
NOTE: New package name to remove redundant 'pushraven' in groupId!
Add Pushraven.jar and it's dependencies to your project. Or add Pushraven as a dependency:
Maven:
<dependency>
<groupId>us.raudi</groupId>
<artifactId>pushraven</artifactId>
<version>1.0.3</version>
</dependency>
Gradle:
compile group: 'us.raudi', name: 'pushraven', version: '1.0.3'
Both of these can be found in your Firebase console, under Project Settings:
Pushraven.setCredential(new File("service_account.json"));
Pushraven.setProjectId("fcmtest-f57d4");
NOTE: A GoogleCredential object may also be used to set the credential.
In Pushraven all the JSON Objects from the API are implemented as classes, and all fields are implemented as methods.
Notification not = new Notification()
.title("Hello World")
.body("This is a notification");
AndroidConfig droidCfg = new AndroidConfig()
.notification(
new AndroidNotification()
.color("#ff0000")
)
.priority(Priority.HIGH);
Message raven = new Message()
.name("id")
.notification(not)
.token(CLIENT_ID) // could instead use: topic(String) or condition(String)
.android(droidCfg);
The FCM API may update and implement new fields which may not have been added to Pushraven yet. You can use the following methods (for any of the constructor classes: Message, Notification, config classes...):
addAttribute(String key, Object value);
addAttributeMap(String key, Map<?, ?> map);
addAttributeArray(String key, Collection<?> arr);
addAttributePayload(String key, Payload payload); // see: Payload.java
Pushraven.push(raven);
// or (if you want to access the response)
FcmResponse response = Pushraven.push(raven);
[1] https://firebase.google.com/docs/reference/fcm/rest/v1/projects.messages