{"id":2287,"date":"2017-01-10T16:13:28","date_gmt":"2017-01-10T10:43:28","guid":{"rendered":"https:\/\/www.innovationm.com\/blog\/?p=2287"},"modified":"2017-01-10T16:13:28","modified_gmt":"2017-01-10T10:43:28","slug":"firebase-push-notification-implementation-in-android-and-app-server","status":"publish","type":"post","link":"https:\/\/www.innovationm.com\/blog\/firebase-push-notification-implementation-in-android-and-app-server\/","title":{"rendered":"Firebase Push Notification Implementation in Android and App Server"},"content":{"rendered":"<h1><b>Introduction<\/b><\/h1>\n<p><span style=\"font-weight: 400;\">I am going to introduce FCM (Firebase Cloud Messaging) implementation in Android app as well as in server side. FCM is a new, improved version of the Google Cloud Messaging (GCM). It has all the features of GCM as well as some additional features. <\/span><\/p>\n<h1><span style=\"color: #3366ff;\"><b>Android\u00a0side\u00a0Implementation (Part 1 &#8211; Registration of app)<\/b><\/span><\/h1>\n<h2><b>1 . <\/b><b>Add Firebase to your Android project<\/b><\/h2>\n<ol>\n<li style=\"font-weight: 400;\"><span style=\"font-weight: 400;\">Add the Android\u00a0project to F<\/span><span style=\"font-weight: 400;\">irebase console. If you already have existing Google project associated with your mobile app, click <\/span><b>Import <\/b><b>Google Project <\/b>else<span style=\"font-weight: 400;\">\u00a0<\/span><b>Create New Project<\/b><span style=\"font-weight: 400;\">.<\/span><\/li>\n<li style=\"font-weight: 400;\"><span style=\"font-weight: 400;\">Click Add Firebase to your Android app and follow the setup process.<\/span><\/li>\n<li style=\"font-weight: 400;\"><span style=\"font-weight: 400;\">At the end, you will dow<\/span><span style=\"font-weight: 400;\">nload <\/span><b>google-services.json<\/b> <span style=\"font-weight: 400;\">file. Yo<\/span><span style=\"font-weight: 400;\">u ca<\/span><span style=\"font-weight: 400;\">n <\/span><span style=\"font-weight: 400;\">download this file<\/span><span style=\"font-weight: 400;\"> again at any time.<\/span><\/li>\n<li style=\"font-weight: 400;\"><span style=\"font-weight: 400;\">Move the <strong>google_services.json<\/strong> file you just downloaded into your Android app module root directory.<\/span><\/li>\n<\/ol>\n<p><a href=\"https:\/\/www.innovationm.com\/blog\/wp-content\/uploads\/2016\/12\/Screenshot-12.png\"><img fetchpriority=\"high\" decoding=\"async\" class=\"wp-image-2292 size-full aligncenter\" src=\"https:\/\/www.innovationm.com\/blog\/wp-content\/uploads\/2016\/12\/Screenshot-12.png\" alt=\"move google_services.json\" width=\"695\" height=\"349\" srcset=\"https:\/\/www.innovationm.com\/blog\/wp-content\/uploads\/2016\/12\/Screenshot-12.png 695w, https:\/\/www.innovationm.com\/blog\/wp-content\/uploads\/2016\/12\/Screenshot-12-300x151.png 300w, https:\/\/www.innovationm.com\/blog\/wp-content\/uploads\/2016\/12\/Screenshot-12-624x313.png 624w\" sizes=\"(max-width: 695px) 100vw, 695px\" \/><\/a><\/p>\n<h2><b>2. <\/b><b>Add Firebase SDK in Android Project in Android Studio<\/b><\/h2>\n<ol>\n<li style=\"font-weight: 400;\"><span style=\"font-weight: 400;\">Add rules to your root &#8211; level<\/span> <b>build.gradle<\/b> <span style=\"font-weight: 400;\">file<\/span><b>\u00a0<\/b><span style=\"font-weight: 400;\">to include the google &#8211; services plugins.<\/span><\/li>\n<li style=\"font-weight: 400;\"><span style=\"font-weight: 400;\">Then, in <\/span><span style=\"font-weight: 400;\">your app-level gradle <\/span><span style=\"font-weight: 400;\">file<\/span> <b>(app\/build.gradle)<\/b><span style=\"font-weight: 400;\">, add apply plugin line at the bottom of the file to enable the Gradle plugin:<\/span><\/li>\n<\/ol>\n<h2><a href=\"https:\/\/www.innovationm.com\/blog\/wp-content\/uploads\/2016\/12\/Screenshot-13.png\"><img decoding=\"async\" class=\"aligncenter wp-image-2294 size-full\" src=\"https:\/\/www.innovationm.com\/blog\/wp-content\/uploads\/2016\/12\/Screenshot-13.png\" alt=\"gradle file\" width=\"671\" height=\"321\" srcset=\"https:\/\/www.innovationm.com\/blog\/wp-content\/uploads\/2016\/12\/Screenshot-13.png 671w, https:\/\/www.innovationm.com\/blog\/wp-content\/uploads\/2016\/12\/Screenshot-13-300x144.png 300w, https:\/\/www.innovationm.com\/blog\/wp-content\/uploads\/2016\/12\/Screenshot-13-624x299.png 624w\" sizes=\"(max-width: 671px) 100vw, 671px\" \/><\/a><\/h2>\n<p><span style=\"font-weight: 400;\">In Android Studio, add the FCM dependency to your app-level <\/span><b>build.gradle<\/b><span style=\"font-weight: 400;\"> file:<\/span><span style=\"font-weight: 400;\">\u00a0 \u00a0<\/span><b>\u00a0 \u00a0\u00a0<\/b><\/p>\n<pre class=\"lang:java decode:true\">dependencies \r\n{\r\n  compile fileTree(dir: 'libs', include: ['*.jar'])\r\n\u00a0\u00a0testCompile 'junit:junit:4.12'\r\n  compile 'com.android.support:appcompat-v7:24.2.0'\r\n \u00a0compile \u00a0\u2018com.google.firebase:firebase-messaging:10.0.1\u2019\r\n}<\/pre>\n<h2><b>3 . <\/b><b>Android code setup for device registration<\/b><\/h2>\n<ol>\n<li style=\"font-weight: 400;\"><span style=\"font-weight: 400;\">Create a service that extends <\/span><b>FirebaseInstanceIdService <\/b><span style=\"font-weight: 400;\">to handle the creation, rotation, and updating of registration tokens. This is required for sending to specific devices or for creating device groups.<\/span><\/li>\n<li style=\"font-weight: 400;\">Add service declaration in app Manifest file.<\/li>\n<\/ol>\n<pre class=\"lang:java decode:true\">&lt;service\r\n android:name=\".MyFirebaseInstanceIDService\"&gt;\r\n\u00a0\u00a0&lt;intent-filter&gt;\r\n      \u00a0&lt;action android:name=\"com.google.firebase.INSTANCE_ID_EVENT\"\/&gt;\r\n \u00a0&lt;\/intent-filter&gt;\r\n&lt;\/service&gt;<\/pre>\n<p><b style=\"font-size: 1.28571rem;\">\u00a0<\/b><b style=\"font-size: 1.28571rem;\">Get the device registration token<\/b><\/p>\n<ol>\n<li style=\"font-weight: 400;\"><span style=\"font-weight: 400;\">If the device doesn&#8217;t have a compatible version of Google Play services, your app can call <\/span><b>GoogleApiAvailability.makeGooglePlayServicesAvailable()<\/b><span style=\"font-weight: 400;\"> to allow users to download Google Play services from the Play Store.<\/span><\/li>\n<li style=\"font-weight: 400;\"><b>onTokenRefresh()<\/b> callback fires whenever a new token is generated. On calling <b>getToken() <\/b>of FirebaseInstanceId you will get a currently available registration token. You can send this to your server.<\/li>\n<\/ol>\n<pre class=\"lang:java decode:true\">@Override\r\npublic void onTokenRefresh() \r\n{\r\n\r\n\u00a0\u00a0\/\/ Get updated InstanceID token.\r\n\r\n    String refreshedToken = FirebaseInstanceId.getInstance().getToken();\r\n   \u00a0Log.w(TAG, \"Refreshed token: \" + refreshedToken);\r\n\r\n\u00a0\u00a0\/\/ If you want to send messages to this application instance or\r\n\u00a0\u00a0\/\/ Instance ID token to your app server.\r\n\r\n   sendRegistrationToServer(refreshedToken);\r\n \u00a0}<\/pre>\n<h1><span style=\"color: #3366ff;\"><b>Server side Implementation<\/b><\/span><\/h1>\n<h2>Infrastructure and Flow of Messages<\/h2>\n<p>There are 2 Entities involved here &#8211; <strong>FCM Server<\/strong> and <strong>Application Server<\/strong><\/p>\n<p><b>FCM Server<\/b><\/p>\n<p><span style=\"font-weight: 400;\">FCM connection servers are provided by Google. These servers take messages from an <\/span><a href=\"https:\/\/firebase.google.com\/docs\/cloud-messaging\/server.html#role\"><span style=\"font-weight: 400;\">app server<\/span><\/a><span style=\"font-weight: 400;\"> and send them to a client app running on a device. Google provides connection servers for <\/span><a href=\"https:\/\/firebase.google.com\/docs\/cloud-messaging\/server#implementing-http-connection-server-protocol\"><span style=\"font-weight: 400;\">HTTP<\/span><\/a><span style=\"font-weight: 400;\"> and <\/span><a href=\"https:\/\/firebase.google.com\/docs\/cloud-messaging\/server#implementing-the-xmpp-connection-server-protocol\"><span style=\"font-weight: 400;\">XMPP<\/span><\/a><span style=\"font-weight: 400;\">.<br \/>\n<\/span><\/p>\n<p><b>Application server<\/b><span style=\"font-weight: 400;\">\u00a0<\/span><\/p>\n<p><span style=\"font-weight: 400;\">App server sends data to a client app via the chosen FCM connection server, using the appropriate XMPP or HTTP protocol.<\/span><\/p>\n<p><strong>Message Flow from Application server to Application on mobile device via FCM Servers<\/strong><\/p>\n<h2><a href=\"https:\/\/www.innovationm.com\/blog\/wp-content\/uploads\/2016\/12\/Firebase-Cloud-Messaging-.jpg\"><img decoding=\"async\" class=\"aligncenter wp-image-2295 size-full\" src=\"https:\/\/www.innovationm.com\/blog\/wp-content\/uploads\/2016\/12\/Firebase-Cloud-Messaging-.jpg\" alt=\"firebase-cloud-messaging\" width=\"615\" height=\"324\" srcset=\"https:\/\/www.innovationm.com\/blog\/wp-content\/uploads\/2016\/12\/Firebase-Cloud-Messaging-.jpg 615w, https:\/\/www.innovationm.com\/blog\/wp-content\/uploads\/2016\/12\/Firebase-Cloud-Messaging--300x158.jpg 300w\" sizes=\"(max-width: 615px) 100vw, 615px\" \/><\/a><b><b><\/b><\/b><\/h2>\n<h2><b><b>Send messages to specific device<\/b><\/b><\/h2>\n<h4><b>Implementation of HTTP connection<\/b><span style=\"font-weight: 400;\">\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0<\/span><\/h4>\n<ol>\n<li style=\"font-weight: 400;\"><span style=\"font-weight: 400;\">First issue a <\/span><b>HTTP GET<\/b><span style=\"font-weight: 400;\"> request to receive user device <\/span><b>REGISTRATION TOKEN<\/b><span style=\"font-weight: 400;\"> along with User_Id to differentiate particular user among all users.<\/span><\/li>\n<li style=\"font-weight: 400;\"><span style=\"font-weight: 400;\">To send a notification message , issue a <\/span><b>HTTP POST <\/b><span style=\"font-weight: 400;\">request. This will hit the FCM server url. \u00a0<\/span><b><a href=\"https:\/\/fcm.googleapis.com\/fcm\/send\">https:\/\/fcm.googleapis.com\/fcm\/send<\/a><\/b><\/li>\n<li style=\"font-weight: 400;\">This request consist two parts : HTTP header and body:<\/li>\n<\/ol>\n<p><strong>HTTP header<\/strong><\/p>\n<p>Header must contain following header:<br \/>\n<span style=\"font-weight: 400;\">(i) Authorization: key= YOUR_SERVER_KEY<\/span><\/p>\n<p><span style=\"font-weight: 400;\">(You may use your <\/span><b>legacy server key<\/b><span style=\"font-weight: 400;\">. \u00a0\u00a0To get this Click <\/span><b>Firebase Console &#8212;&gt; Project Name &#8212;-&gt; Cloud Messaging Tab (you will get your server key)<\/b><span style=\"font-weight: 400;\"> )<\/span><\/p>\n<h2><a href=\"https:\/\/www.innovationm.com\/blog\/wp-content\/uploads\/2016\/12\/Screenshot-16.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter wp-image-2293 size-full\" src=\"https:\/\/www.innovationm.com\/blog\/wp-content\/uploads\/2016\/12\/Screenshot-16.png\" alt=\"screenshot-16\" width=\"1329\" height=\"571\" srcset=\"https:\/\/www.innovationm.com\/blog\/wp-content\/uploads\/2016\/12\/Screenshot-16.png 1329w, https:\/\/www.innovationm.com\/blog\/wp-content\/uploads\/2016\/12\/Screenshot-16-300x129.png 300w, https:\/\/www.innovationm.com\/blog\/wp-content\/uploads\/2016\/12\/Screenshot-16-1024x440.png 1024w, https:\/\/www.innovationm.com\/blog\/wp-content\/uploads\/2016\/12\/Screenshot-16-624x268.png 624w\" sizes=\"(max-width: 1329px) 100vw, 1329px\" \/><\/a><\/h2>\n<p><span style=\"font-weight: 400;\">(ii) Content-Type: application\/json for JSON; application\/x-www-form-urlencoded;charset=UTF-8 for plain text.\u00a0<\/span><\/p>\n<p><span style=\"font-weight: 400;\">If Content-Type is omitted, the format is assumed to be plain text.<\/span><\/p>\n<p><strong>HTTP Body<\/strong><\/p>\n<ul>\n<li style=\"font-weight: 400;\"><span style=\"font-weight: 400;\">To send message to specific devices , set \u201c<\/span><b>to\u201d \u00a0<\/b><span style=\"font-weight: 400;\">key to the registration to token for the specific app instance.<\/span><\/li>\n<\/ul>\n<p><b>HTTP POST Request (final structure)<\/b><\/p>\n<pre class=\"lang:default decode:true\">https:\/\/fcm.googleapis.com\/fcm\/send\r\nContent-Type:application\/json\r\nAuthorization:key=AZVHGDG-7726:FE663RFT44R4\r\n\r\n{ \r\n\"data\": \r\n  {\r\n  \"score\": \"r5t5t\",\r\n  \u00a0\"time\": \"15:26\"\r\n \u00a0},\r\n\"to\" : \"fhtryvu78647f457f356c65v75uvb76b87bu87..\"\r\n}\r\n\r\n<\/pre>\n<h2><b><b>Send messages to device groups<\/b><\/b><\/h2>\n<p><span style=\"font-weight: 400;\">Basically Group refers as a set of different devices. All devices in a group share a notification key, which is the token that FCM uses to send messages to all devices in that group.<\/span><\/p>\n<p><span style=\"font-weight: 400;\">The limit on data payload is 2KB when sending to iOS devices, and 4KB for other platforms. The maximum number of members allowed for a notification_key is 20.<\/span><\/p>\n<p><b>1.\u00a0<\/b><b>Manage device groups<\/b><\/p>\n<ul>\n<li style=\"font-weight: 400;\"><span style=\"font-weight: 400;\">First get all registration tokens which you want to add in a group.<\/span><\/li>\n<li style=\"font-weight: 400;\"><span style=\"font-weight: 400;\">Create a <\/span><b>Notification_key , <\/b><span style=\"font-weight: 400;\">which indicate the device group. You can generate this notification_key on App server as well as on your Android client app.<\/span><\/li>\n<li style=\"font-weight: 400;\"><span style=\"font-weight: 400;\">You can remove, create, and update devices in a particular group.<\/span><\/li>\n<\/ul>\n<p><b>2.\u00a0<\/b><b>Create device groups<\/b><\/p>\n<ul>\n<li style=\"font-weight: 400;\"><span style=\"font-weight: 400;\">To create a device group, send a <\/span><b>POST<\/b><span style=\"font-weight: 400;\"> request that provides a <\/span><b>name for the group<\/b><span style=\"font-weight: 400;\">, and a list of registration tokens for the devices. FCM returns a <\/span><b>new notification_key<\/b><span style=\"font-weight: 400;\"> that represents the device group.<\/span><\/li>\n<li style=\"font-weight: 400;\"><span style=\"font-weight: 400;\">Send a request like<\/span>\u00a0<b style=\"font-size: 1rem;\">\u00a0<\/b><a style=\"font-size: 1rem;\" href=\"https:\/\/android.googleapis.com\/gcm\/notification\"><b>https:\/\/android.googleapis.com\/gcm\/notification<\/b><\/a><\/li>\n<\/ul>\n<p><b>HTTP POST Request<\/b><\/p>\n<pre class=\"lang:java decode:true\">https:\/\/android.googleapis.com\/gcm\/notification\r\nContent-Type:application\/json\r\nAuthorization:key=API_KEY\r\nproject_id:SENDER_ID\r\n{\r\n   \"operation\": \"create\",\r\n   \"notification_key_name\": \"appUser-Chris\",\r\n   \"registration_ids\": [\"4\", \"8\", \"15\", \"16\", \"23\", \"42\"]\r\n}\r\n<\/pre>\n<ul>\n<li style=\"font-weight: 400;\"><span style=\"font-weight: 400;\">The notification_key_name and notification_key are unique to a group of registration tokens.It is important that notification_key_name is unique per client app if you have multiple client apps for the same sender ID.<\/span><\/li>\n<\/ul>\n<p><b>Response Format<\/b><\/p>\n<p><span style=\"font-weight: 400;\">A successful request returns a notification_key like the following:<\/span><\/p>\n<pre class=\"lang:java decode:true\">{\r\n\r\n\u00a0\u00a0\"notification_key\": \"HFDSGFJHGR...735735FGFHGFJGKHGGGG\"\r\n\r\n}<\/pre>\n<ul>\n<li style=\"font-weight: 400;\"><span style=\"font-weight: 400;\">Save the notification_key and the corresponding notification_key_name to use in subsequent operations.<\/span><\/li>\n<\/ul>\n<p><b>3. <\/b><b>Sending downstream messages to device groups<\/b><\/p>\n<ul>\n<li style=\"font-weight: 400;\"><span style=\"font-weight: 400;\">Sending messages to a device group is very similar to sending messages to an individual device. Set the to parameter<\/span><b> \u201cto\u201d<\/b><span style=\"font-weight: 400;\"> the unique notification key for the device group.<\/span><\/li>\n<\/ul>\n<p><b>\u00a0HTTP POST Request<\/b><\/p>\n<pre class=\"lang:default decode:true\">https:\/\/fcm.googleapis.com\/fcm\/send\r\nContent-Type:application\/json\r\nAuthorization:key=AIzaSyZ-1u...0GBYzPu7Udno5aA\r\n{\r\n\u00a0\"to\": \"aUniqueKey\",\r\n \"data\":\r\n {\r\n  \u00a0\"hello\": \"This is a test message for Firebase Cloud Messaging Device Group Message!\",\r\n\u00a0}\r\n}<\/pre>\n<h1><span style=\"color: #3366ff;\"><b>Android\u00a0side\u00a0Implementation (Part 2 &#8211; Receiving Push Notification)<\/b><\/span><\/h1>\n<p><span style=\"font-weight: 400;\">A service that extends <\/span><b>FirebaseMessagingService<\/b><span style=\"font-weight: 400;\">. This is required if you want to do any message handling beyond receiving notifications on apps in the background ,to receive notifications in foregrounded apps, to receive data payload, to send upstream messages, and so on, you must extend this service.<\/span><\/p>\n<h3>Add the following code to your app\u2019s manifest:<\/h3>\n<pre class=\"lang:java decode:true\">&lt;service\r\n      android:name=\".MyFirebaseMessagingService\"&gt;\r\n   \u00a0&lt;intent-filter&gt;\r\n         \u00a0&lt;action android:name=\"com.google.firebase.MESSAGING_EVENT\"\/&gt;\r\n  \u00a0\u00a0&lt;\/intent-filter&gt;\r\n&lt;\/service&gt;<\/pre>\n<h3><b>Code Sample for receiving notification and generate local notification:<\/b><\/h3>\n<pre class=\"lang:java decode:true\">public class MyFirebaseMessagingService extends FirebaseMessagingService\r\n\r\n{\r\n\r\nprivate static final String TAG = \"MyFirebaseMsgService\";\r\n\r\n\u00a0@Override\r\n  public void onMessageReceived(RemoteMessage remoteMessage)\r\n         {\r\n             super.onMessageReceived(remoteMessage);\r\n\r\n\u00a0          \/\/ TODO(developer): Handle FCM messages here.\r\n           \/\/ Not getting messages here? See why this may be: https:\/\/goo.gl\/39bRNJ\r\n\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0    Log.d(TAG, \"From: \" + remoteMessage.getFrom());\r\n\r\n          \/\/ Check if message contains a data payload.\r\n\r\n\u00a0\u00a0\u00a0\u00a0\u00a0    \u00a0if (remoteMessage.getData().size() &gt; 0) {\r\n           \u00a0Log.d(TAG, \"Message data payload: \" + remoteMessage.getData());\r\n\r\n\u00a0\u00a0\u00a0\u00a0\u00a0    \u00a0}\r\n\r\n\r\n   \u00a0\/\/ Check if message contains a notification payload.\r\n\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0if (remoteMessage.getNotification() != null) \r\n      {\r\n        Log.d(TAG, \"Message Notification Body: \" + remoteMessage.getNotification().getBody());\r\n   \u00a0   sendNotification(remoteMessage.getNotification().getBody());\r\n\r\n       }\r\n\r\n      \/\/ Also if you intend on generating your own notifications as a result of a received \u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0FCM\r\n     \/\/ message, here is where that should be initiated. See sendNotification method below.\r\n    \u00a0\u00a0}\r\n\r\n\u00a0   \u00a0\/\/ [END receive_message]\r\n\r\n\r\n\u00a0\u00a0\/**\r\n\r\n\u00a0\u00a0\u00a0* Create and show a simple notification containing the received FCM message.\r\n\r\n\u00a0\u00a0\u00a0*\r\n\r\n\u00a0\u00a0\u00a0* @param messageBody FCM message body received.\r\n\r\n\u00a0\u00a0\u00a0*\/\r\n\r\n\r\n\u00a0\u00a0private void sendNotification(String messageBody) {\r\n\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0Intent intent = new Intent(this, MainActivity.class);\r\n\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);\r\n\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0PendingIntent pendingIntent = PendingIntent.getActivity(this, 0 \/* Request code *\/, intent,\r\n\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0PendingIntent.FLAG_ONE_SHOT);\r\n\r\n\r\n\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0Uri defaultSoundUri= RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);\r\n\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(this)\r\n\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0.setSmallIcon(R.drawable.ic_launcher)\r\n\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0.setContentTitle(\"FCM Message\")\r\n\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0.setContentText(messageBody)\r\n\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0.setAutoCancel(true)\r\n\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0.setSound(defaultSoundUri)\r\n\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0.setContentIntent(pendingIntent);\r\n\r\n   \u00a0NotificationManager notificationManager =\r\n\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0(NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);\r\n\r\n    notificationManager.notify(0 \/* ID of notification *\/, notificationBuilder.build());\r\n\r\n\u00a0\u00a0}\r\n\r\n\u00a0\r\n\r\n<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>Introduction I am going to introduce FCM (Firebase Cloud Messaging) implementation in Android app as well as in server side. FCM is a new, improved version of the Google Cloud Messaging (GCM). It has all the features of GCM as well as some additional features. Android\u00a0side\u00a0Implementation (Part 1 &#8211; Registration of app) 1 . Add [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":2311,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[2,71],"tags":[],"class_list":["post-2287","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-android","category-mobile"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v27.3 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>Firebase Push Notification Implementation in Android and App Server<\/title>\n<meta name=\"description\" content=\"Guide on implementing Firebase Push Notification in Android and App Server.\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/www.innovationm.com\/blog\/firebase-push-notification-implementation-in-android-and-app-server\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Firebase Push Notification Implementation in Android and App Server\" \/>\n<meta property=\"og:description\" content=\"Guide on implementing Firebase Push Notification in Android and App Server.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.innovationm.com\/blog\/firebase-push-notification-implementation-in-android-and-app-server\/\" \/>\n<meta property=\"og:site_name\" content=\"InnovationM - Blog\" \/>\n<meta property=\"article:published_time\" content=\"2017-01-10T10:43:28+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/www.innovationm.com\/blog\/wp-content\/uploads\/2016\/12\/Firebase-messaging.png\" \/>\n\t<meta property=\"og:image:width\" content=\"696\" \/>\n\t<meta property=\"og:image:height\" content=\"569\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/png\" \/>\n<meta name=\"author\" content=\"InnovationM Admin\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"InnovationM Admin\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"7 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\\\/\\\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\\\/\\\/www.innovationm.com\\\/blog\\\/firebase-push-notification-implementation-in-android-and-app-server\\\/#article\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/www.innovationm.com\\\/blog\\\/firebase-push-notification-implementation-in-android-and-app-server\\\/\"},\"author\":{\"name\":\"InnovationM Admin\",\"@id\":\"https:\\\/\\\/www.innovationm.com\\\/blog\\\/#\\\/schema\\\/person\\\/a831bf4602d69d1fa452e3de0c8862ed\"},\"headline\":\"Firebase Push Notification Implementation in Android and App Server\",\"datePublished\":\"2017-01-10T10:43:28+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\\\/\\\/www.innovationm.com\\\/blog\\\/firebase-push-notification-implementation-in-android-and-app-server\\\/\"},\"wordCount\":909,\"commentCount\":0,\"image\":{\"@id\":\"https:\\\/\\\/www.innovationm.com\\\/blog\\\/firebase-push-notification-implementation-in-android-and-app-server\\\/#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/www.innovationm.com\\\/blog\\\/wp-content\\\/uploads\\\/2016\\\/12\\\/Firebase-messaging.png\",\"articleSection\":[\"Android\",\"Mobile\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\\\/\\\/www.innovationm.com\\\/blog\\\/firebase-push-notification-implementation-in-android-and-app-server\\\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\\\/\\\/www.innovationm.com\\\/blog\\\/firebase-push-notification-implementation-in-android-and-app-server\\\/\",\"url\":\"https:\\\/\\\/www.innovationm.com\\\/blog\\\/firebase-push-notification-implementation-in-android-and-app-server\\\/\",\"name\":\"Firebase Push Notification Implementation in Android and App Server\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/www.innovationm.com\\\/blog\\\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\\\/\\\/www.innovationm.com\\\/blog\\\/firebase-push-notification-implementation-in-android-and-app-server\\\/#primaryimage\"},\"image\":{\"@id\":\"https:\\\/\\\/www.innovationm.com\\\/blog\\\/firebase-push-notification-implementation-in-android-and-app-server\\\/#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/www.innovationm.com\\\/blog\\\/wp-content\\\/uploads\\\/2016\\\/12\\\/Firebase-messaging.png\",\"datePublished\":\"2017-01-10T10:43:28+00:00\",\"author\":{\"@id\":\"https:\\\/\\\/www.innovationm.com\\\/blog\\\/#\\\/schema\\\/person\\\/a831bf4602d69d1fa452e3de0c8862ed\"},\"description\":\"Guide on implementing Firebase Push Notification in Android and App Server.\",\"breadcrumb\":{\"@id\":\"https:\\\/\\\/www.innovationm.com\\\/blog\\\/firebase-push-notification-implementation-in-android-and-app-server\\\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\\\/\\\/www.innovationm.com\\\/blog\\\/firebase-push-notification-implementation-in-android-and-app-server\\\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/www.innovationm.com\\\/blog\\\/firebase-push-notification-implementation-in-android-and-app-server\\\/#primaryimage\",\"url\":\"https:\\\/\\\/www.innovationm.com\\\/blog\\\/wp-content\\\/uploads\\\/2016\\\/12\\\/Firebase-messaging.png\",\"contentUrl\":\"https:\\\/\\\/www.innovationm.com\\\/blog\\\/wp-content\\\/uploads\\\/2016\\\/12\\\/Firebase-messaging.png\",\"width\":696,\"height\":569},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/www.innovationm.com\\\/blog\\\/firebase-push-notification-implementation-in-android-and-app-server\\\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\\\/\\\/www.innovationm.com\\\/blog\\\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Firebase Push Notification Implementation in Android and App Server\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\\\/\\\/www.innovationm.com\\\/blog\\\/#website\",\"url\":\"https:\\\/\\\/www.innovationm.com\\\/blog\\\/\",\"name\":\"InnovationM - Blog\",\"description\":\"\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\\\/\\\/www.innovationm.com\\\/blog\\\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Person\",\"@id\":\"https:\\\/\\\/www.innovationm.com\\\/blog\\\/#\\\/schema\\\/person\\\/a831bf4602d69d1fa452e3de0c8862ed\",\"name\":\"InnovationM Admin\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/5c99d9eece9dfbc82297cf34ddd58e9fe05bb52fe66c8f6bf6c0a45bfb6d7629?s=96&r=g\",\"url\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/5c99d9eece9dfbc82297cf34ddd58e9fe05bb52fe66c8f6bf6c0a45bfb6d7629?s=96&r=g\",\"contentUrl\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/5c99d9eece9dfbc82297cf34ddd58e9fe05bb52fe66c8f6bf6c0a45bfb6d7629?s=96&r=g\",\"caption\":\"InnovationM Admin\"},\"sameAs\":[\"http:\\\/\\\/www.innovationm.com\\\/\"],\"url\":\"https:\\\/\\\/www.innovationm.com\\\/blog\\\/author\\\/innovationmadmin\\\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Firebase Push Notification Implementation in Android and App Server","description":"Guide on implementing Firebase Push Notification in Android and App Server.","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/www.innovationm.com\/blog\/firebase-push-notification-implementation-in-android-and-app-server\/","og_locale":"en_US","og_type":"article","og_title":"Firebase Push Notification Implementation in Android and App Server","og_description":"Guide on implementing Firebase Push Notification in Android and App Server.","og_url":"https:\/\/www.innovationm.com\/blog\/firebase-push-notification-implementation-in-android-and-app-server\/","og_site_name":"InnovationM - Blog","article_published_time":"2017-01-10T10:43:28+00:00","og_image":[{"width":696,"height":569,"url":"https:\/\/www.innovationm.com\/blog\/wp-content\/uploads\/2016\/12\/Firebase-messaging.png","type":"image\/png"}],"author":"InnovationM Admin","twitter_misc":{"Written by":"InnovationM Admin","Est. reading time":"7 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/www.innovationm.com\/blog\/firebase-push-notification-implementation-in-android-and-app-server\/#article","isPartOf":{"@id":"https:\/\/www.innovationm.com\/blog\/firebase-push-notification-implementation-in-android-and-app-server\/"},"author":{"name":"InnovationM Admin","@id":"https:\/\/www.innovationm.com\/blog\/#\/schema\/person\/a831bf4602d69d1fa452e3de0c8862ed"},"headline":"Firebase Push Notification Implementation in Android and App Server","datePublished":"2017-01-10T10:43:28+00:00","mainEntityOfPage":{"@id":"https:\/\/www.innovationm.com\/blog\/firebase-push-notification-implementation-in-android-and-app-server\/"},"wordCount":909,"commentCount":0,"image":{"@id":"https:\/\/www.innovationm.com\/blog\/firebase-push-notification-implementation-in-android-and-app-server\/#primaryimage"},"thumbnailUrl":"https:\/\/www.innovationm.com\/blog\/wp-content\/uploads\/2016\/12\/Firebase-messaging.png","articleSection":["Android","Mobile"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/www.innovationm.com\/blog\/firebase-push-notification-implementation-in-android-and-app-server\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/www.innovationm.com\/blog\/firebase-push-notification-implementation-in-android-and-app-server\/","url":"https:\/\/www.innovationm.com\/blog\/firebase-push-notification-implementation-in-android-and-app-server\/","name":"Firebase Push Notification Implementation in Android and App Server","isPartOf":{"@id":"https:\/\/www.innovationm.com\/blog\/#website"},"primaryImageOfPage":{"@id":"https:\/\/www.innovationm.com\/blog\/firebase-push-notification-implementation-in-android-and-app-server\/#primaryimage"},"image":{"@id":"https:\/\/www.innovationm.com\/blog\/firebase-push-notification-implementation-in-android-and-app-server\/#primaryimage"},"thumbnailUrl":"https:\/\/www.innovationm.com\/blog\/wp-content\/uploads\/2016\/12\/Firebase-messaging.png","datePublished":"2017-01-10T10:43:28+00:00","author":{"@id":"https:\/\/www.innovationm.com\/blog\/#\/schema\/person\/a831bf4602d69d1fa452e3de0c8862ed"},"description":"Guide on implementing Firebase Push Notification in Android and App Server.","breadcrumb":{"@id":"https:\/\/www.innovationm.com\/blog\/firebase-push-notification-implementation-in-android-and-app-server\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.innovationm.com\/blog\/firebase-push-notification-implementation-in-android-and-app-server\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.innovationm.com\/blog\/firebase-push-notification-implementation-in-android-and-app-server\/#primaryimage","url":"https:\/\/www.innovationm.com\/blog\/wp-content\/uploads\/2016\/12\/Firebase-messaging.png","contentUrl":"https:\/\/www.innovationm.com\/blog\/wp-content\/uploads\/2016\/12\/Firebase-messaging.png","width":696,"height":569},{"@type":"BreadcrumbList","@id":"https:\/\/www.innovationm.com\/blog\/firebase-push-notification-implementation-in-android-and-app-server\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/www.innovationm.com\/blog\/"},{"@type":"ListItem","position":2,"name":"Firebase Push Notification Implementation in Android and App Server"}]},{"@type":"WebSite","@id":"https:\/\/www.innovationm.com\/blog\/#website","url":"https:\/\/www.innovationm.com\/blog\/","name":"InnovationM - Blog","description":"","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.innovationm.com\/blog\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Person","@id":"https:\/\/www.innovationm.com\/blog\/#\/schema\/person\/a831bf4602d69d1fa452e3de0c8862ed","name":"InnovationM Admin","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/secure.gravatar.com\/avatar\/5c99d9eece9dfbc82297cf34ddd58e9fe05bb52fe66c8f6bf6c0a45bfb6d7629?s=96&r=g","url":"https:\/\/secure.gravatar.com\/avatar\/5c99d9eece9dfbc82297cf34ddd58e9fe05bb52fe66c8f6bf6c0a45bfb6d7629?s=96&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/5c99d9eece9dfbc82297cf34ddd58e9fe05bb52fe66c8f6bf6c0a45bfb6d7629?s=96&r=g","caption":"InnovationM Admin"},"sameAs":["http:\/\/www.innovationm.com\/"],"url":"https:\/\/www.innovationm.com\/blog\/author\/innovationmadmin\/"}]}},"_links":{"self":[{"href":"https:\/\/www.innovationm.com\/blog\/wp-json\/wp\/v2\/posts\/2287","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.innovationm.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.innovationm.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.innovationm.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.innovationm.com\/blog\/wp-json\/wp\/v2\/comments?post=2287"}],"version-history":[{"count":0,"href":"https:\/\/www.innovationm.com\/blog\/wp-json\/wp\/v2\/posts\/2287\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.innovationm.com\/blog\/wp-json\/wp\/v2\/media\/2311"}],"wp:attachment":[{"href":"https:\/\/www.innovationm.com\/blog\/wp-json\/wp\/v2\/media?parent=2287"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.innovationm.com\/blog\/wp-json\/wp\/v2\/categories?post=2287"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.innovationm.com\/blog\/wp-json\/wp\/v2\/tags?post=2287"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}