To send push notifications using FCM, an app server is required, I’m completely new to programming and all I can do is write a little Java and don’t understand the concept of servers.

What kind of server is it, where should it be registered, in the application or is it something that should communicate with the application from the outside? There is a lot of information on the Internet, according to what needs to be registered in the server, but all these examples assume that I have a general idea of ​​what a server is and that I have it. Just from what I read, it follows that this server needs to be written not in java, but for example in php, if so, how can I connect it in my application?

I myself am surprised at what a stupid question turned out, but I can’t even formulate it normally, because I don’t understand what this server is.

In general, I would be grateful for any information about what is the app server used when working with FCM on android.

    1 answer 1

    You correctly understood that the App server needed in order to communicate with the application from the outside. When you get a token in your application, you send it to the server. Thus, the server can send you push-notifications for this token.

    Here is an example on Node js :

     var gcm = require('node-gcm'); var API_KEY = "yourApiKey"; var sender = new gcm.Sender(API_KEY); //объект сообщения var message = new gcm.Message({ collapseKey: 'data', priority: 'high', contentAvailable: true, delayWhileIdle: false, timeToLive: 1000 data: { message: 'Message from gcm server', action: 'Update data on server' }, notification: { tag : 'hasData', title: "Title text", icon: "ic_launcher", color: "#22C064", sound: "notification_sound", body: "This is a GCM notification that will be displayed ASAP.", click_action: "OPEN_APP" // make intent-filter in Manifest.xml for this action } }); //Список токенов которым будут отправлены сообщения var registrationTokens = []; registrationTokens.push('owQMHz9-Ep6FtiB-pp9uFcZTKcdvUhrsG3XdL7IWgZSt8cWfASzPPxEW1cBdLn1OUukqfsk9rlTexO3MQ0EeSdLXaAFXQn7vYzrKG1LTnv8LOxkBQqEd0VnxLd4'); //отправить на конкретные девайсы sender.send(message, { registrationTokens: registrationTokens }, function (err, response) { if(err){ console.error(err); } else{ console.log(response); } }); //отправить на все устройства которые подписаны на этот топик sender.send(message, {to : "/topics/global" }, function (err, response) { if(err){ console.error(err); } else{ console.log(response); } }); 
    • Thank you so much for the answer! I understand correctly that what you have just written is the implementation of the app server? Are the tokens sent from the application to the GCM server? - Mikhail
    • Most importantly, I cannot understand whether the app server is being written in android studio or not, and if not, where? - Mikhail
    • Tokens are sent to your app server. It is simply not shown here, in fact from the application you need to send, for example, a POST request with a token and the server saves it, i.e in the registrationTokens.push ('owQMHz9-) row, I just manually token the token, in fact it could pull up from the database, and it was saved to the database at the moment you sent it to the server from the application. - Kirill Stoianov
    • Looking at what you will write it, but I do not think that AS is a suitable tool for this. I use Node Js for the server to write it in WebStorm (JetBrains), Sublime, Atom. Well, this is a matter of taste, even in a notebook. - Kirill Stoianov
    • All early I can not understand where the server will be after you write it. But this is already my problem, you explain well, it’s just difficult for me to understand all this. Thanks again! - Mikhail