how to send notification to android app from server

Hiii everyone in this article I am sharing how to send notification to the android app from the server. Now we’ll create a simple app that receives a firebase push notification from both the firebase console and from the PHP code. It’s very easy to used google FCM for push notification in android.

1. First thing you need to do is go to and make an account to gain access to their console. After you gain access to the console you can start by creating your first project.


If you choose to create a new project, you need to set the project name. For example, 


 Select “Add Firebase to your Android app”





Add App package name and. I only set my package name and SHA-1 because I don’t use Firebase for my app’s authentication.


Click the ADD APP button here to download google-services.json. This is an important file and you will need to put it into your app.

2. Add google-services.json to your app folder

Replace the google-services.json in your app folder. The Google services plugin for Gradle will load the google-services.json file you just downloaded.

3. Configure gradle files

Open Android Studio and modify your build.gradle files to use the Google services plugin.

3.1  Add the Google services plugin in your Project-based build.gradle.

classpath ''

3.2 Add the Google FCM plugin in your App Base build.gradle. 

compile ''
compile ''
apply plugin: ''

 4. Then add it into the AndroidManifest.xml file.

<service android:name=".Firebase.MyFirebaseMessagingService">
        <action android:name="" />
<service android:name=".Firebase.MyFirebaseInstanceIDService">
        <action android:name="" />


After you can create a java class for FirebaseMessagingService. and generate a token key for used backend Noficiation

5. Add a service that extends  MyFirebaseInstanceIDService  java class

public class MyFirebaseInstanceIDService extends FirebaseInstanceIdService {

    private static final String TAG = "MyAndroidFCMIIDService";

    public void onTokenRefresh() {
        //Get hold of the registration token
        String refreshedToken = FirebaseInstanceId.getInstance().getToken();
        SessionManagement sessionManagement = new SessionManagement();
        //Log the token
        Log.d(TAG, "Refreshed token: " + refreshedToken);
    private void sendRegistrationToServer(String token) {
        //Implement this method if you want to store the token on your server

6. Add a Notification Handel java class  MyFirebaseMessagingService  java class

public class MyFirebaseMessagingService extends FirebaseMessagingService {
    private static final String TAG = "MyAndroidFCMService";
    public void onMessageReceived(RemoteMessage remoteMessage) {
        // Check if message contains a data payload.
        if (remoteMessage.getData().size() > 0) {
            Log.d(TAG, "Message data payload: " + remoteMessage.getData());

        //create notification

        //Calling method to generate notification
            //Log data to Log Cat
            Log.d(TAG, "From: " + remoteMessage.getFrom());
            Log.d(TAG, "Notification Message Body: " + remoteMessage.getNotification().getBody());


    private void createNotification( String messageBody) {
        Intent intent = new Intent( this , HomeActvity. class );
        PendingIntent resultIntent = PendingIntent.getActivity( this , 0, intent, PendingIntent.FLAG_ONE_SHOT);
        Uri notificationSoundURI = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);
        long[] v = {200,500};
        NotificationCompat.Builder mNotificationBuilder = new NotificationCompat.Builder( this)
        NotificationManager notificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);

complete integration Test and send your first push notification

you can go your firebase console and login open your project and inside the navigation bar select Cloud Messaging


Happy Coding!!!!! All the Best


You may also like...