Android TutorialsNo Comments

Andrologo.png
1221 views.

Firebase Cloud Messaging (FCM) is a cross-platform messaging solution that lets you reliably deliver messages at no cost.

Using FCM, you can notify a client app that new email or other data is available to sync. You can send notification messages to drive user re-engagement and retention. For use cases such as instant messaging, a message can transfer a payload of up to 4KB to a client app.

Creating an Android Studio Project

Creating an Android Project once the project is created copy the package name then go to developer console with below link and their create a project with same package

https://console.firebase.google.com/?pli=1

fire1

Now put your app name and select your country.

fire2

Now click on Add Firebase to Your Android App.

add-firebase-to-android

Now you have to enter your projects package name and click on ADD APP.

firebase-cloud-messaging-tutorial-2

fter clicking add app you will get google-services.json file.
Adding Firebase Messaging to Your Project
Now come back to your android project. Go to app folder and paste google-services.json file.

firebase-cloud-messaging-tutorial-3

Now go to your root level build.gradle file and add the following code.

Inside app level build.gradle file make the following changes.

Now sync your project.
Implementing Firebase Cloud Messaging

Create a class named MyFirebaseInstanceIDService.java and write the following code.

Now create MyFirebaseMessagingService.java and write the following code.

Now we have to define the above services in our AndroidManifest.xml file. So go to manifest and modify as follows.

Thats all. Now run your app .
After running you will see the token in the logcat. Copy the token.

firebase-cloud-messaging-tutorial-4

Sending Push Notification using Firebase Console
Go to firebase console and select the app you created.
From the left menu select notification.
Click on new message.
Enter message, select single device and paste the token you copied and click on send. The same as I did on the video, and check your device

firebase-cloud-messaging-tutorial-5

 

Be the first to post a comment.

Add a comment