Support me through paypal :
========= paypal.me/CoderVlog
My favorite Gadgets :
1. keyboard : https://amzn.to/3dh2AMS
2. Mic : https://amzn.to/2WACxKD
3. Laptop : https://amzn.to/2UeJMGF
4. DSLR : https://amzn.to/2UBmFVU
5. Mobile : https://amzn.to/3boSNTn
6. Mouse : https://amzn.to/2WBO4JK
blog link : https://tii.ai/xamVq
Official Website : https://codervlogs.info
official programming facebook page : / saify333
official personal facebook page :
/ saify3333
follow me on Instagram :
/ saify9999
how to add push notification feature in your android app, I see a lot of tutorial on firebase push notification but they are sending notification from firebase console, not from android app. So today, I will create app to app firebase android notification. In which user can send notification from android device not firebase console to specific android device.
We will be using retrofit library in android which help you to do http request and callback, so you can retrieve data from online firebase with few line of code.
Firebase has already build in feature of push notification, you need to do is add firebase could messaging dependency in android gradle and sync the project to download library.
First I will talk on what is concept of firebase push notification then I will discussed on practical example of firebase push notification. So in the firebase push there are two things Notification model and Data model, Notification model carries data a notification while Data model carries normal data that can be used for intent, sqlite database and many other operation. Why notification model or Data model is separated, because in firebase when is in background, you can not use data model unless your app is in foreground therefore, notification model is separated and it is automatically used when your app is in background, create auto notification and taking data from notification model. You will be confused now with notification model or data model but later in practical example it is cleared in coding.
See in the above picture, there are two app state, in which firebase push notification work differently in these two app state, one is foreground app state and other is background app state. According to documentation, when your app is in foreground state then you will get both notification data and payload data, similarly when app is in background state, only notification data will be delivered. There is special way to handle firebase push notification when your app is in background state. I will explain further in code (practical implementation).
Last thing to clarify is token, well in this app, you will send notification to specific device and in order to send notification to particular device you need token of that device, to get token write this code