Integrate Firebase Push Notifications in Android Application
1) Introduction of the tools (here Android N and IDE you are going to use)
2) Setting up the environment.
In Android Studio, create a new project by navigating to File ⇒ New Project and fill all the required details. When it prompts to select a default activity, select Blank Activity and proceed.
In this tutorial you can learn how to integrate Firebase Push Notifications in android application.
The Google IO 2017 announced the use of FIREBASE in ANDROID. Google has moved from GCM that is Google Cloud Messaging to FCM that is FIREBASE CLOUD MESSAGING.
Firebase helps to build android apps better. Firebase allows to create a wide range to apps.
Let’s check out what FIREBASE provides for the development of an application.
Here is the list :
- Realtime Database
- Crash Reporting
- Cloud Functions
- Cloud Storage
- Test Lab for Android
- Performance Monitoring
- Google Analytics
- Cloud Messaging
- Dynamic Links
- Remote Config
- App Indexing
We will check with a simple demo on REGISTRATION AND LOGIN by using ANDROID FIREBASE.
Register firebase: On your project in the android studio. As simple as that.
Let’s proceed with the practical. Here, step by step we will create the project and run on a real android device.
STEPS FOR FIREBASE AUTHENTICATION IN ANDROID APP DEVELOPMENT:
1. Create a Project in Android Studio
2. Select your Platform and proceed.
3. Now You have one Activity. We are going to setup FIREBASE now.
4. For setting up the FIREBASE, go to TOOLS=>FIREBASE
5. Here, the window of firebase opens up and select the tool that you want to use. So, lets select the notification of firebase.
6. Once you click on the "receive the notification", the window will be opened with the suggestions. Now click on "connect to firebase"
Now it will ask to create a project on firebase
Click on “CONNECT TO FIREBASE”.
As soon as the firebase is connected, it will show “CONNECTED” as above.
7. Now click on “ADD NOTIFICATIONS TO THE APP”. It will open a dialog asking for accept changes.
So click on “ACCEPT CHANGES”
8. By including this dependency, the app is ready to get the notifications as the set us is done.
9. Now create a new class MyFirebaseInstanceIDService
10. After creating this class, extend the class to FirebaseInstanceIdService.
11. Import com.google.firebase.iid.FirebaseInstanceIdService
12. Now in manifest file add the snippet : By adding this, we are registering the service in manifest file.
13. Now add the methods as below:
These methods are used for getting the token from device.
14. Now add the service for getting the notifications from the server.
15. Create a new java class MyFirebaseMessagingService and extend it to FirebaseMessagingService.
In this service, we add two methods:
a) onMessageReceived(RemoteMessage remoteMessage) and
b) sendNotification(String messageBody)
16. Now add the following snippet in manifest file:
17. Now we implement the methods:
18. Now we create notification for getting the message from server
19. Now open the firebase console: https://console.firebase.google.com/
Either you can create new project or you can use the project created from the android studio itself.
20. Once you click on the project, a new window opens:
On the left sided panel, there is a tab of notification, Click on the "NOTIFICATIONS"
Click on "Send your first message" and a new window will be opened where you can write the message.
Add the message and click on send message
And then you are done with the coding. This is how we can implement the android firebase push notifications.
I hope this blog post will help you to how to Integrate Firebase Push Notification in Android. Let me know in a comment if you have any questions regarding Android. I will reply you ASAP.
Top-5 Best Mobile Application Development Platform in 2022
It is not an exaggeration to say that Android is the most popular mobile OS with 85% market share and north of 5 million apps in the Google...
What are Android Emulators and How to Setup an Android Emulator?
There are a variety of reasons why you would want to run an Android emulator on your PC. Mobile app developers always look to test their app...