FCM (Firebase Cloud Messaging) Push Notification to Android Device using PHP API

FCM( Firebase Cloud messaging) is used to send notification to android device. FCM also provide storage for user data, token service, analysis user pattern and many more. FCM is free for limited use. This blog demonstrate how to configure FCM with android app and PHP API. It is very easy and simple to intergrate push notification using FCM( Firebase Cloud messaging). In this blog we will build a user registration android app to our PHP Server and at same time FCM( Firebase Cloud messaging) configuration done in background. After successful login a push notification send to user device contains welcome message via firebase api. Your can also send notification using Firebase console. Below is detail of step follow in this tutorial.

1) Create Firebase login and get json file from google.
2) Configure FCM in android studio Gradle file.
3) Firebase Message type.
4) Setup android project to receive notification.
5) Run App in Real Device using USB Debugging.

Android Device get push notification from PHP Server Using Firebase cloud messaging(FCM)

Login & Download source code


50 days android course



1. Create Firebase login and get JSON file

Before start firebase first create new project in android studio.Because android project package name will be needed in Firebase.
1. Now you need to do is go to https://firebase.google.com/ and make an account to gain access to their console. After that you can start by creating your first project.

2. Give the package name of your project (i used blueappsoftware.firenotification ) to get configure JSON file from Firebase. then download the google-services.json file and place this file inside “app” folder of your android studio project that you are going to create in next step.

3. Create a new project in Android Studio from File ⇒ New Project. While filling the project details, use the same package name which you gave in firebase console. Like my android project name is blueappsoftware.firenotification . Place the downloaded file google-services.json inside “app” folder of android studio project.

2. Configure FCM in android studio Gradle file

1. Open build.gradle(Module:app) file in android studio. Add this line at the end of file.

2. Now open project gradle file build.gradle(Project) in android studio. Add this line in dependency

Firebase Message Type

Firebase Cloud Messaging have two type of messaging services. 1) Notification Message 2) Data Message
Firebase Document says”Use notification messages when you want FCM to handle displaying a notification on your client app’s behalf. Use data messages when you want to process the messages on your client app.
The app server can send a message including both notification and data payloads. In such cases, FCM handles displaying the notification payload, and the client app handles the data payload”.

Notification message

Data message

Setup android project to receive notification

Now to start app development. create two java class file. first one for getting token from FCM server and second java class file for receiving notification from either Firebase console or from our own PHP server.


This java file get FCM token from Firebase server when app install on user device. Token automatically update from Firebase server.


This java file responsible for receiving notification from Firebase console or PHP server. Remember if you are using notification type FCM message and if app is in background(generally it is background) then this java file will not execute onMessageReceived(RemoteMessage remoteMessage) method. So my best advice to you is always use Data type FCM message, so your app will receive notification every time whether app is either in foreground or in background.

gradle file app module


MainActivity.java file only containing two textview. first one display token id from firebase console.

Server side code

Now we will develop our own server so that each token store in mysql databse and we will send notification form our server without going to Firebase console. first create table in mysql


This PHP file received token from android device and store FCM token into mysql database.

Database connection file

Send Notification from PHP server

This PHP file display a form to send notification to android device. Fill all the details in this form.
1)Title that display in notification bar in android phone.
2) Subtitle- small text below title line
3) Image that display in notification
4) Extra message for app as body
5) select User token OR select user unique ID from mysql database to whose you want to send notification.
6) To make your form safe use any private key here. Remember First edit this key in FirebaseServerMultiple.php file as you want.

When you want to send notification just open this file in web browser. Fill all details select user unique id from mysql database. OR you can edit this code to select user token only from mysql databse.


Run App in Real Device using USB Debugging

Login & Download source code


Posted in andorid and tagged , , .

kamal bunkar

I Am Post Graduation (M.Tech. C.S.E) from VNIT, Nagpur. I Have Published Two Research Paper On International Journal. My Apps on Google Play Store- Sanyukt Parivar(Mp Police ), NOTOtag- Digital Chhindwara, The Tubby-VoiceRecognizer & More.
Contact me at kamal.bunkar@blueappsoftware.in


  1. I love your blog.. very nice colors & theme. Did you create this
    website yourself or did you hire someone to do it for you?
    Plz respond as I’m looking to create my own blog and would like to find
    out where u got this from. appreciate it

  2. Pretty great post. I just stumbled upon your weblog and wanted to say
    that I’ve truly loved browsing your blog posts.
    In any case I’ll be subscribing for your feed and I hope you write once more very soon!

  3. Hi there! This post could not be written any better!
    Reading through this post reminds me of my good old room mate!
    He always kept talking about this. I will forward this article to him.
    Fairly certain he will have a good read. Thank you for sharing!

  4. Hi there! Quick question that’s totally off topic.
    Do you know how to make your site mobile friendly?
    My weblog looks weird when browsing from my iphone4.
    I’m trying to find a template or plugin that might
    be able to fix this issue. If you have any recommendations, please share.
    Thank you!

  5. This is really attention-grabbing, You are an overly skilled blogger.
    I have joined your feed and look forward to in the hunt
    for extra of your great post. Also, I have shared your site in my social networks

  6. I’m really enjoying the theme/design of your blog.

    Do you ever run into any browser compatibility issues?

    A few of my blog audience have complained about my site not
    working correctly in Explorer but looks great in Chrome.
    Do you have any solutions to help fix this issue?

  7. I was recommended this web site by my cousin. I’m
    not sure whether this post is written by him as no one else
    know such detailed about my problem. You are wonderful!


  8. Hey I know this is off topic but I was wondering if you knew of any widgets I could add to my blog that automatically tweet my newest twitter updates.
    I’ve been looking for a plug-in like this for quite some time and was hoping maybe you would have some experience with something like this.
    Please let me know if you run into anything. I truly enjoy reading your
    blog and I look forward to your new updates.

  9. Having read this I thought it was very informative. I appreciate you finding the time and
    energy to put this short article together. I once again find myself personally spending a lot of time both reading and posting comments.
    But so what, it was still worthwhile!

  10. hi! may i know is your code complete? because i run the program and does nothing, i have download the given source code.

    • Yes this code is working…You have to create file on php server to store FCM key into your database for future use. First check on your android studio log whether FCM token is printing OR not. If it is printing in log than send token to your web server.

  11. Good day! I could have sworn I’ve been to
    this website before but after going through
    a few of the articles I realized it’s new to me.

    Nonetheless, I’m certainly delighted I found it and I’ll be book-marking it and checking back regularly!

  12. Spot on with this write-up, I absolutely feel this website needs much more attention. I’ll probably be returning to read
    through more, thanks for the info!

  13. Hey very cool website!! Man .. Excellent ..
    Amazing .. I will bookmark your site and take the feeds additionally?
    I am glad to search out numerous useful info here
    in the submit, we need work out more strategies
    on this regard, thanks for sharing. . . . . .

  14. Pingback: ExoPlayer Android Example- Best Alternative of VideoView By Kamal

  15. Pingback: Simplest way to get WordPress Post in Android App- REST API

  16. I just like the helpful information you supply to your articles.

    I’ll bookmark your blog and test once more here frequently.
    I’m fairly sure I will learn many new stuff proper here!
    Good luck for the following!

Comments are closed.