Firebase is a mobile application development toolkit created by the Google that helps the programmers quickly develop high-quality mobile apps, grow the user base, and earn extra cash by displaying ads via AdMob. It has everything you need to get started, from build, maintain to scale a mobile app on all major platforms like Android, iOS, Windows etc.
A step-by-step guide to implement FCM notifications in back-end PHP application.
This is the second part of tutorial on Firebase Cloud Messaging (FCM) integration with Android application. In first part, we discussed FCM integration with Android app that consists of following four steps:
- Prerequisites
- Add Firebase to your Android project
- Setup FCM SDK in your project
- Access Device Registration Token
In order to proceed with FCM server side integration, I recommend completing the first part if you’ve done it yet. Let’s talk about our last step to send push notification from our server to any client device.
About FCM Server
The server side of FCM consists of two main components:
- FCM connection servers provided by Google. These servers take messages from an app server and send them to a client app running on a device. Google provides connection servers for HTTP and XMPP.
- An app server that you must implement in your environment. This app server sends data to a client app via the chosen FCM connection server, using the appropriate XMPP or HTTP protocol.
A full FCM implementation requires both a client implementation and a server implementation to work perfectly.
App Server Implementation in Java
Following Java code snippet does the job of sending a push notification from app server to a client device:
// Method to send Notifications from server to client end.
public final static String AUTH_KEY_FCM = "xyxyxyxxyxyxyxyxyxyxyxy";
public final static String API_URL_FCM = "https://fcm.googleapis.com/fcm/send";
// userDeviceIdKey is the device id you will query from your database
public static void pushFCMNotification(String userDeviceIdKey) throws Exception{
String authKey = AUTH_KEY_FCM; // You FCM AUTH key
String FMCurl = API_URL_FCM;
URL url = new URL(FMCurl);
HttpURLConnection conn = (HttpURLConnection) url.openConnection();
conn.setUseCaches(false);
conn.setDoInput(true);
conn.setDoOutput(true);
conn.setRequestMethod("POST");
conn.setRequestProperty("Authorization","key="+authKey);
conn.setRequestProperty("Content-Type","application/json");
JSONObject json = new JSONObject();
json.put("to",userDeviceIdKey.trim());
JSONObject info = new JSONObject();
info.put("title", "Notificatoin Title"); // Notification title
info.put("body", "Hello Test notification"); // Notification body
json.put("notification", info);
OutputStreamWriter wr = new OutputStreamWriter(conn.getOutputStream());
wr.write(json.toString());
wr.flush();
conn.getInputStream();
}
Send Message to Device Groups
Sending messages to a device group is very similar to sending messages to an individual device. Set the to
parameter to the unique notification key for the device group.
json.put("to", "aUniqueKey"); //replace userDeviceIdKey with the unique notification key for the group
This completes the Android Push Notifications using Firebase tutorial. I hope, it has helped you to setup a basic understanding of what FCM is and how it is integrated in mobile apps.
Continue Reading: FCM Push Notifications: Receive Messages in an Andriod App
Need further help? If you’re confused or facing any issue while completing first step, let’s know in comments.
How to send to all devices rather than single for group of devices
Genetic Viagra Using Mastercard
Please let me know if you’re looking for a article author for
your weblog. You have some really great posts and I think I would be a good asset.
If you ever want to take some of the load off, I’d really like to write
some material for your blog in exchange for a link back to mine.
Please blast me an email if interested. Thanks! http://herreramedical.org/prednisone
Kamagra World
Priligy
generic plaquenil
cialis 1mg
seroquel online order
cost cialis daily use
cialis without prescription
cheapest tadalafil cost tadalafil online
instagram hacklink satın al.
cialis without a prescription tadalafil daily online
instagram hacklink hizmetleri satın alarak sosyal medyanızı büyütün.
tadalafil price walmart generic cialis online fast shipping
Rexbet Canlı Bahis Rexbet Canlı Bahis menüsü de Türkiye’deki tüm bahisçileri 12’den vurmuş durumda. Öncelikle belirtmek isterim ki, sitenin canlı bahis ara yüzü neredeyse mükemmele yakın durumda. Burada canlı bahis oynamanın keyfini sonuna kadar hissedeceğine bahse girebilirim. Rexbet canlı bahis keyfi bir başka.
how To Get Medi Care To Pay For Cialis?
Hi, just required you to know I he added your site to my Google bookmarks due to your layout. But seriously, I believe your internet site has 1 in the freshest theme I??ve came across.