I am new to using FCM notifications for an Android app at https://firebase.google.com/docs/cloud-messaging/server . I read about it and found that the requirements for the About FCM server page say the following:
An application server that you must implement in your environment. This server application sends data to the client application through the selected FCM server connection using the appropriate XMPP or HTTP protocol.
However, I am very confused about this. As I read more in the article, I see that there is an API that looks like this:
POST http://fcm.googleapis.com/fcm/send
If I call this API using something like OkHttpClient and build my request like this (assuming I have authentication headers and a POST body)
private void sendRegistrationToServer(String token) { OkHttpClient client = new OkHttpClient(); RequestBody body = new FormBody.Builder().add("Body", "").build(); //Assuming I have authentication and body put in Request request = new Request.Builder().url("http://fcm.googleapis.com/fcm/send").post(body).build(); try { client.newCall(request).execute(); } catch (IOException e) { e.printStackTrace(); } }
Will I, in theory, be able to send a notification with any information I want on this device? I can receive a message through the following class:
public class NotificationService extends FirebaseMessagingService { ...
I am sure that my understanding is incorrect somewhere, as the documentation says that we need an application server, but if someone could indicate where I do not understand how to implement FCM notifications, that would be great. If someone could give an example of where or when we need an application server, or how it should actually be implemented, this would also be highly appreciated. Thanks!
source share