Android Firebase Push Notification To Multiple Devices From Server(PHP-MySQL)

Hi Android geeks. Android firebase push notification tutorial for multiple devices is here.

In this Android firebase push notification tutorial, we will send push notification to single or multiple devices from server(PHP-MySQL.)

This Android firebase push notification is developed using Android Studio and JAVA.

If you don’t want to send notification from server, then check Firebase cloud messaging Android.

First, check the output of Android firebase push notification example then we will develop it.

Download Source Code for Android firebase push notification

[sociallocker] Download FCMMultiple [/sociallocker]

Step 1: Create a new project in Android Studio.

A new Android Studio project with empty activity is required for this project. So create it first.

Step 2: Working with Firebase Console

Following video will guide you to develop app in firebase console.

Learning Easy steps of firebase console video

  1. Go to https://firebase.google.com/ and sign in to your google account.
  2. Click on Add Project and give project name and country.
  3. Click on CREATE PROJECT button.
  4. After project is created, click on Add firebase to your Android app button.
  5. Give your Android package name and click on Register App button.
  6. Click on Download google-services.json button.
  7. Move your downloaded JSON file into app folder of your android project as shown in the video.

Step 3: Changing build.gradle(Project: project_name) file:

Add following in dependencies{} structure

So last source code for build.gradle(Project: project_name)  is:

Step 4:Changing build.gradle(Module:app) file

Copy below into dependencies{}

Step 5: Developing Service Classes

Developing GettingDeviceTokenService

Make a new JAVA class named GettingDeviceTokenService”  and copy following

Device token is found in this service.

Developing NotificationService

Create a new JAVA class named NotificationService” and add below source code

Description of NotificationService

remoteMessage.getData().toString() will give us JSON data as following

Following source code will parse above JSON data

Now following source will decide whether user has sent image with notification or not.

If image is not sent, then generateNotification() will be run.

Otherwise notificationWithImage() will be run.

getBitmapFromURL() method will give us bitmap of image(Popey Image.)

Now consider below source code

Above code will decide which activity to open when user clicks on Push Notification.

Here GotNotificationActivity will be open. So let’s create GotNotificationActivity.

Create a new activity named GotNotificationActivity and update activity_got_notification.xml as follow:

Developing Server Side(PHP) script to send firebase push notification

Create a new PHP file and name it sendMultipleFCM.php

Add below source code into it

I have save above file here in my server: https://demonuts.com/Demonuts/JsonTest/Tennis/sendMultipleFCM.php

Upgrade above file where there is a code like

header(“Location: https://demonuts.com/Demonuts/JsonTest/Tennis/sendMultipleFCM.php”)

with your server path or localhost path.

Testing your push notification without creating PHP Script

If you want to send push notification directly to your android device, then go to

https://www.demonuts.com/Demonuts/JsonTest/Tennis/sendMultipleFCM.php

Fill required details (Firebase Server Key, Device Tokens etc.) and click on the Go Go Go button.

Provide two device tokens to get notifications on them.

You can also enter only device token and keep another empty. Of course Notification will be sent to only one device.

Use comment section to give your review or to ask any question.

So all for Android firebase push notification programmatically example tutorial. Thank you.

Hardik Parsania

I am mobile app developer. I am always passionate about solving complex and real world problems.I have developed many apps with great interest and superior logical skills.

You may also like...

1 Response

  1. sirisha says:

    how to send notification to app background when the database value changes,it means I tried notification and firebase cm ,firebase console and php server side coding and node js but can’t get solution,please anybody help me sending push notifications automatically to android app(in background) when the database value changes i used mysql database server

Leave a Reply

Your email address will not be published. Required fields are marked *