Push Notification in Android using Firebase Cloud Messaging?

Are you thinking about building a mobile application? Firebase Cloud Messaging (FCM) can help!  FCM lets you send messages to your app users. It catches their attention and sends important messages or information. 

With FCM, you can reach your app users and keep them coming back for more! FCM also allows sending Push notifications using an app server. 

Here Firebase SDK is used. the example given below in detail. 

Step 1: Open the Firebase console  with this link https://firebase.google.com/


Step 2: Open the Firebase console and log in with the existing login and other wish signup.


Step 3: Now create a new project of FCM and follow the below step.


Step 4: Fill in the mobile application project name of FCM.

 

Step 5: In this step, we can use the analytics of the project and switch on the Enable Google Analytics for this project option. 


Step 6: when enabling Google Analytics for this project is disabled.


Step 7: Create the project process mentioned below.


Step 8: After finishing the process click to continue.


Step 9: Dashboard of FCM.


Step 10: Now select a platform like Android app development, iOS, etc.


Step 11: Create an app when selecting the platform.


Step 12: The next step is to add your IOS and Android packager name.


12.1:  android  package  name


12.2:  App nickname(optional) 


12.3:  Debug signing certificate SHA-1 (optional)


Step 13: After adding the package if the other option is filled other wish it is optional, and click on register app.


Step 14: Now click on the next button showing the Android android studio or IOS code.


Step 15: Now click on the next button.


Step 16: Last step of FCM and click on Continue to console.


Step 17: Now open Android Studio and open an existing project otherwise create a new project.


Step 18: 

18 .1: Create one class that contains FCM code like (FirebaseMessagingService)

class FirebaseMessagingService : FirebaseMessagingService() {

This method was used to receive notifications at that time.

override fun onMessageReceived(rm: RemoteMessage) {

       // Put Your code in on the message method

}

This method used to create new Token 

override fun onNewToken(token: String) { 

super.onNewToken(token)

       // This method is used for 

 }

}

18.2: The below code put in your Android studio manifest file

 <service android:name=".fcm.MyFirebaseMessagingService" android:enabled="true" android:exported="true" android:permission="com.google.android.c2dm.permission.SEND"> 

<intent-filter>

 <action android:name="com.google.firebase.MESSAGING_EVENT" /> 

<action android:name="com.google.android.c2dm.intent.RECEIVE" /> 

<action android:name="com.google.firebase.INSTANCE_ID_EVENT" />

 </intent-filter>

 </service>

Congratulations! You've now completed your Firebase Push Notification set-up!






365Bloggy May 2, 2024
Share this post
Tags
SUBSCRIBE THIS FORM


Archive