Firebase push notifications update DB
As per my experience with Firebase push:
Problem: When sending push notification through "Firebase console", notification is only received when application is in foreground. If the application is killed or in background, the notification is shown only in Version >= lollipop with incorrect notification icon and/or opening the default launcher activity in the app even if you have defined different Activity in PendingIntent.
As per Firebase docs, a push message is divided into 2 pars, they call them: Docs Link here
- notification
- data payload
Solution:
There are two ways to send a "Push" message.
1. Firebase Console
2. Messaging API - Image showing a request using Advanced REST Client
Push message is received in onMessageReceived(...)
method. Firebase onMessageReceived(...)
method will not get called if the app is in background or killed only when the message is sent through Firebase Console.
If you send the message via API, it works fine. Message is delivered in onMessageReceived(...)
method whether app is in background, foreground or killed. (Caution: This is working fine in >=Lollipop
- Behaviour for Android 4.4 or below is still unpredictable.
Update:
You can send a push message from API (firebase call it downstream msg) like this: https://firebase.google.com/docs/cloud-messaging/downstream
Sending downstream messages from the server
To address or "target" a downstream message, the app server sets to with the receiving client app's registration token. You can send notification messages with predefined fields, or custom data messages; see Notifications and data in the message payload for details on payload support. Examples in this page show how to send data messages in HTTP and XMPP protocols.
HTTP POST Request
https://fcm.googleapis.com/fcm/send
Content-Type:application/json
Authorization:key=AIzaSyZ-1u...0GBYzPu7Udno5aA
{ "data": {
"score": "5x1",
"time": "15:10"
},
"to" : "bk3RNwTe3H0:CI2k_HHwgIpoDKCIZvvDMExUdFQ3P1..."
}
How to update app database with push notification with length 4kb
The best practice in such cases is to avoid sending the whole payload through the push message.
Instead, you should send only the data needed to identify the changed data and make the app request the updates directly from the server.
Related Topics
Retrofit Uploading Multiple Images to a Single Key
Alarmmanager Android Every Day
Android: Create Circular Image with Picasso
What Is the Default Font Family in Android
Eclipse, Android, Scala Made Easy But Still Does Not Work
How to Replace Deprecated Android.Support.V4.App.Actionbardrawertoggle
Facebook Authentication Without Login Button
Can You Launch the Native Camera App from an HTML 5 Web App
App Not Setup: This App Is Still in Development Mode
Official "Boost Library" Support for Android and iOS
Display Huge Images in Android
How to Pause Flash Content in an Android Webview When My Activity Isn't Visible
How to Know Which Intent Is Selected in Intent.Action_Send
Mediaplayer Error (1, -1004) Aka Media_Error_Io Trying to Stream Music on Samsung S3
Play Sound on Phonegap App for Android
Unregistered_On_Api_Console While Getting Oauth2 Token on Android
How to Have a Gridview That Adapts Its Height When Items Are Added