Android App Development
iOS App Development
Flutter App Development
Cross Platform App Development
Hire on-demand project developers and turn your idea into working reality.
Big thanks to Webkul and his team for helping get Opencart 3.0.3.7 release ready!
Deniel Kerr
Founder. Opencart
Top Partners
We all love to enable the firebase push notification in our android application.
But while looking at the documents and prescribed content, one might be confused many a times as in what exactly is the right approach to send a notification.
In this blog, we will learn two ways of sending a push notification to your android application using firbase push notification.
Prerequisite :
Now looking at the approaches, the first approach is pretty simple and officially recommended. Lets have a look at this :
Approach 1 :
CODE :
Well, that’s it . You can now send the Push notification.
APPROACH 2 :
That’s it, the second approach is done.
NOTE: Saving SERVER API KEY in code is not recommended by the FIREBASE.
For getting where exactly thye serverkey is on firebase console ,you can have a look at this screenshot.
Your email address will not be published. Required fields are marked*
Name*
Email*
Save my name email and website in this browser for the next time I comment.
Can you share the code you have written?
data.put(“sound”, YOUR_SOUND_REFRENCE); data.put(“icon”, YOUR_ICON_REFRENCE);
Only these small changes should do.
If in case these don’t work then you can also try sending these in the notification payload parallel to the data payload only.
For that, you will have to do something like this : JSONObject data = new JSONObject(); data.put(“title”, YOUR_TITLE); data.put(“body”, YOUR_CONTENT); data.put(“sound”, YOUR_SOUND_REFRENCE); data.put(“icon”, YOUR_ICON_REFRENCE);
JSONObject notification_data = new JSONObject(); notification_data.put(“data”, data); notification_data.put(“notification”, data); notification_data.put(“to”,YOUR_DEVICE_TOKEN_OR_NOTIFICATION_KEY);
And then use the above-mentioned snippet.
NOTE: 1) The sound to play when the device receives the notification.
Supports “default” or the filename of a sound resource bundled in the app. Sound files must reside in /res/raw/.
2) The notification’s icon.
Sets the notification icon to myicon for drawable resource myicon. If you don’t send this key in the request, FCM displays the launcher icon specified in your app manifest.
Thanks, Anchit
We use cookies to personalize your experience. By continuing to visit this website you agree to our use of cookies. Learn more about privacy policy
Name
Email
Subject
Enquiry or Requirement
If you have more details or questions, you can reply to the received confirmation email.