Send notifications from your android to other devices
- User segment
- Topic
- A single device
Download via gradle:
In file build.gradle (Module: app) :
dependencies {
implementation 'com.github.DavidBarbaran:FCM-AndroidToOtherDevice:1.1.2'
}
and in the file build.gradle (Project) :
allprojects {
repositories {
maven { url 'https://jitpack.io' }
}
}
How to get firebase server key?
FirebasePush.build("SERVER_KEY")
.setNotification(Notification("FCM-AndroidToOtherDevice", "This is a body"))
.sendToTopic("news")
- Using in Kotlin:
val notification = Notification("FCM-AndroidToOtherDevice", "This is a body")
val yourExtraData = JSONObject().put("key", "name")
val firebasePush = FirebasePush.build("SERVER_KEY")
.setNotification(notification)
.setData(yourExtraData)
.setOnFinishPush { onFinishPush() }
// Send to topic
firebasePush.sendToTopic("news")
// or send to token
firebasePush.sendToToken("firebaseTokenId")
// or send to user segment
val jsonArray = JSONArray();
jsonArray.put("firebaseTokenId1")
jsonArray.put("firebaseTokenId2")
jsonArray.put("firebaseTokenId3")
firebasePush.sendToGroup(jsonArray)
- Using in Java:
FirebasePush firebasePush = new FirebasePush("SERVER_KEY");
firebasePush.setAsyncResponse(new PushNotificationTask.AsyncResponse() {
@Override
public void onFinishPush(@NotNull String ouput) {
Log.e("OUTPUT", ouput);
}
});
firebasePush.setNotification(new Notification("title","body"));
// Send to topic
firebasePush.sendToTopic("news");
// or send to token
firebasePush.sendToToken("firebaseTokenId");
// or send to user segment
JSONArray jsonArray = new JSONArray();
jsonArray.put("firebaseTokenId1");
jsonArray.put("firebaseTokenId2");
jsonArray.put("firebaseTokenId3");
firebasePush.sendToGroup(jsonArray);
Advanced use of Notification:
val notification = Notification("title", "body","icon", "sound.mp3","SplashActivity")
// or
val notification = Notification()
notification.title = "title"
notification.body = "body"
notification.icon = "icon"
notification.sound = "sound.mp3"
notification.clickAction = "SplashActivity"
notification.color = "#000000"
notification.tag = "youtTag"
notification.bodyLocalizationKey = "bodyLocalizationKey"
notification.titleLocalizationKey = "titleLocalizationKey"
Found a bug or a problem on a specific feature? Open an issue on Github issues