Reputation: 183
I am working on two applications simultaneously in Android. One is suppose 'App A', another 'App B'. I want to send data, such as profile picture & name, from App A (in device A) to App B (in device B) in form of Push Notification, which will be sent by App A and received by App B. All this will be done through FCM. Can anyone suggest me the technical approach I should follow? Any kind of link will also be helpful.
Upvotes: 0
Views: 1541
Reputation: 8396
There are few many steps involved in the process that you would like to do, I'll try to mention some of the general steps.
Both apps need to be integrated with Firebase and linked to one shared project. This is so that they can access and communicate.
After registration of each app on each device with FCM, you would have unique identifies (registration token) for each app/device. You need to find a way to communicate this with the other device which can be through a shared firebase database or by any other mean you see fit.
Then you can use the REST api of Firebase to send your push notification to the targeted device here is the documentation
now with these said, you need to double check to see why you need to send push notification in the first place, because if your goal is to communicate, then you should figure that out to accomplish the task number 2 mentioned above.
Upvotes: 0
Reputation: 184
I have made 2 different apps which communicate through notifications
Here's how:
Note this is just a psudo code using rxjava and retrofit 2.0
Your code me depend on what you use
In your retrofit instance:
note: https://fcm.googleapis.com is the base url
retrofit = new Retrofit.Builder()
.baseUrl("https://fcm.googleapis.com")
.client(getHttp())
.addConverterFactory(GsonConverterFactory.create())
.addCallAdapterFactory(RxJavaCallAdapterFactory.create())
.build();
service = retrofit.create(SendMsgService.class);
Then in your service class:
@POST("/fcm/send")
rx.Observable<Message> sendMsg(@Header("Authorization") String auth,
@Body Message Message);
Your DataModel class(Here to,data,message_id are few pre-defined parameters in fcm):
@SerializedName("to")
@Expose
private String to;
@SerializedName("data")
@Expose
private NotifyData notification;
@SerializedName("message_id")
@Expose
private String message_id;
public Message(String to, NotifyData notification, String message_id) {
this.to = to;
this.notification = notification;
this.message_id = message_id;
}
public String getTo() {
return to;
}
public void setTo(String to) {
this.to = to;
}
public NotifyData getNotification() {
return notification;
}
public void setNotification(NotifyData notification) {
this.notification = notification;
}
public String getMessage_id() {
return message_id;
}
public void setMessage_id(String message_id) {
this.message_id = message_id;
}
Then call your API:
sendMsgBtn.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
NotifyData notifydata = new NotifyData("Notification title","Notification body");
subscription.add(sendMsgViewModel.sendMsg("key=YOUR_KEY_HERE"
,new Message("fcm_id_of_other_device_you_want_to_send_notification"
,notifydata,""))
.subscribe(new Observer<Message>() {
@Override
public void onCompleted() {
}
@Override
public void onError(Throwable e) {
}
@Override
public void onNext(Message message) {
}
}));
}
});
Upvotes: 1
Reputation: 81
it is possible send push notifications from an Android app, you need make it with API REST,
as in this answer
Firebase : Send notification with REST API
you could make something similar, but using asynctask in android or retrofit for make requests from android.
You could not send pictures, but you can send url with pictures location, and then download it.
you could send it to another devide with another app installed, but you need to have the device token.
Read FCM documentation about API parameters.
Upvotes: 0