onMessageRecieved never fired Firebase notifications

how to handle notification when app in background in firebase ios
firebase notification when app is killed android
push notification not received when app is closed in android firebase
firebase notification android
how to handle notification when app in foreground in firebase android
firebase push notification limit
firebase notification vs data message
firebase push notification character limit

my on MessageRecieved method never gets fired in my Android app although the service is running and the manifest seems to be fine. We are sending messages through the firebase console and nothing ever seems to happen. Also the onToken refresh method is only ever called once and that is when you first install the application. After that, it is never called. I have tested the app in the foreground and background and still the onMessageRecieve method is not called.

Here is my manifest

        <?xml version="1.0" encoding="utf-8"?>
    <manifest xmlns:android="http://schemas.android.com/apk/res/android"
        xmlns:tools="http://schemas.android.com/tools"
        package="com.example.beatrice.mylocalbartender">

        <application
            android:allowBackup="true"
            android:icon="@mipmap/ic_launcher"
            android:label="@string/app_name"
            android:supportsRtl="true"
            android:theme="@style/AppTheme"
            tools:node="replace"
            tools:replace="android:supportsRtl">

            <!-- meta data to connect ot the facebook api -->

            <service
                android:enabled="true"
                android:exported="true"
                android:name=".messaging.MyFirebaseInstanceIdService">
                <intent-filter>
                    <action android:name="com.google.firebase.INSTANCE_ID_EVENT"/>
                </intent-filter>
            </service>

            <service
                android:enabled="true"
                android:exported="true"
                android:name=".messaging.MyFirebaseMessagingService">
                <intent-filter>
                    <action android:name="com.google.firebase.MESSAGING_
    EVENT"/>
                </intent-filter>
            </service>


            <meta-data
                android:name="com.google.firebase.messaging.default_notification_icon"
                android:resource="@drawable/bt_ic_android_pay" />
            <!-- Set color used with incoming notification messages. This is used when no color is set for the incoming
                 notification message.  for more. -->
            <meta-data
                android:name="com.google.firebase.messaging.default_notification_color"
                android:resource="@color/colorAccent" />


            <meta-data android:name="com.facebook.sdk.ApplicationId" android:value="@string/facebook_app_id"/>
            <meta-data android:name="com.google.android.gms.wallet.api.enabled" android:value="true"/>
            <meta-data android:name="com.google.android.gms.version" android:value="@integer/google_play_services_version" />




            <uses-permission android:name="android.permission.INTERNET" />

            <activity android:name=".messaging.MainActivity"></activity>
            <activity android:name=".activity.GmailSignInActivity">

            </activity>

            <activity android:name=".activity.MainActivity">

                <intent-filter>
                    <action android:name="android.intent.action.MAIN" />

                    <category android:name="android.intent.category.LAUNCHER" />
                </intent-filter>

            </activity>

            <!-- activity for brain tree, please do not touch -->
            <activity
                android:name="com.braintreepayments.api.BraintreeBrowserSwitchActivity"
                android:launchMode="singleTask">
                <intent-filter>
                    <action android:name="android.intent.action.VIEW" />

                    <category android:name="android.intent.category.DEFAULT" />
                    <category android:name="android.intent.category.BROWSABLE" />

                    <data android:scheme="${applicationId}.braintree" />
                </intent-filter>
            </activity>

            <!-- This activity will be removed in the future -->

            <activity
                android:name=".activity.FacebookLogInActivity"
                android:label="@string/title_activity_facebook_log_in"
                android:theme="@style/AppTheme.NoActionBar">

            </activity>


            <!-- to launch facebook activity - please do not touch -->

            <activity android:name="com.facebook.FacebookActivity"
                android:configChanges="keyboard|keyboardHidden|screenLayout|screenSize|orientation"
                android:theme="@android:style/Theme.Translucent.NoTitleBar"
                android:label="@string/app_name" />

            <activity enter code hereandroid:name="com.braintreepayments.api.dropin.DropInActivity"></activity>
            <activity android:name="com.braintreepayments.api.dropin.AddCardActivity"></activity>



        </application>

    </manifest>

As you can see the services are enabled and exported. Here are the services

public class MyFirebaseInstanceIdService extends FirebaseInstanceIdService {

    private static final String TAG = "MyFirebaseIIDService";
    private static final String FRIENDLY_ENGAGE_TOPIC = "friendly_engage";

    /**
     * The Application's current Instance ID token is no longer valid
     * and thus a new one must be requested.
     */

    public MyFirebaseInstanceIdService(){
        super();
        Log.d("startedServiceNoLie","hiiiiiiiiiiiiiiiiiiiii");
    }


    @Override
    public void onTokenRefresh() {
        // If you need to handle the generation of a token, initially or
        // after a refresh this is where you should do that.
        String token = FirebaseInstanceId.getInstance().getToken();

        Log.d(TAG, "FCM Token: " + token);
    }
}

And this is the FirebaseMessagingService

public class MyFirebaseMessagingService extends FirebaseMessagingService {

    private static final String TAG = "MyFMService";

    public MyFirebaseMessagingService() {
        super();
        Log.d("startedMessageRecieved","messagingService");

    }

    @Override
    public void onMessageReceived(RemoteMessage remoteMessage) {
        // Handle data payload of FCM messages.
        Log.d("messageRecieved", "FCM Message Id: " + remoteMessage.getMessageId());
        Log.d("messageRecieved", "FCM Notification Message: " +
                remoteMessage.getNotification());
        Log.d("messageRecieved", "FCM Data Message: " + remoteMessage.getData());
    }
}

And this is the activity from where is both services are being called from

    public class MainActivity extends AppCompatActivity {

    Button launch_msg_app;
   // private static DatabaseReference root = FirebaseDatabase.getInstance().getReference();

    @Override
    protected void onCreate(Bundle savedInstanceState) {

        FirebaseApp.initializeApp(this);
        super.onCreate(savedInstanceState);
        setContentView(R.layout.deletethislayout);

        Intent intent = new Intent(this, MyFirebaseInstanceIdService.class);

        Log.d("tokenNotRefresh",FirebaseInstanceId.getInstance().getToken());
        startService(intent);


        startService(new Intent(this, MyFirebaseMessagingService.class));

        //startService(new Intent(this, DeleteService.class));
    }

Here is my project . gradle

buildscript {
    repositories {
        jcenter()
        maven { url 'https://maven.fabric.io/public' }
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:2.2.3'
        classpath 'com.google.gms:google-services:3.0.0'
        // NOTE: Do not place your application dependencies here; they belong
        // in the individual module build.gradle files
    }
}

allprojects {
    repositories {
        jcenter()
        mavenLocal()
        maven {
            url 'https://maven.fabric.io/public'
        }
    }
}

task clean(type: Delete) {
    delete rootProject.buildDir
}

Here is my app .gradle

    apply plugin: 'com.android.application'

    repositories {
        mavenLocal()
        flatDir {
            dirs 'libs'
        }
    }
    android {
        compileSdkVersion 25
        buildToolsVersion "25.0.2"

        defaultConfig {
            applicationId "com.example.beatrice.mylocalbartender"
            minSdkVersion 16
            targetSdkVersion 25
            versionCode 1
            versionName "1.0"
            testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
        }
        buildTypes {
            release {
                minifyEnabled false
                proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
            }
        }
    }


    dependencies {
        compile fileTree(dir: 'libs', include: ['*.jar'])
        testCompile 'junit:junit:4.12'
        compile 'com.google.android.gms:play-services:10.2.0'

        compile 'com.android.support:design:25.0.0'
        compile 'com.github.bumptech.glide:glide:3.6.1'
        compile 'de.hdodenhof:circleimageview:1.3.0'
        compile 'com.android.support:appcompat-v7:25.0.0'

        // Google
        compile 'com.google.android.gms:play-services-auth:10.2.0'

        // Firebase
        compile 'com.google.firebase:firebase-core:10.2.0'
        compile 'com.google.firebase:firebase-messaging:10.2.0'
        compile 'com.google.firebase:firebase-database:10.0.0'
        compile 'com.google.firebase:firebase-auth:10.0.0'
        compile 'com.google.firebase:firebase-config:10.0.0'
        compile 'com.google.android.gms:play-services-appinvite:10.2.0'
        compile 'com.google.android.gms:play-services-ads:10.2.0'
        compile 'com.google.firebase:firebase-crash:10.0.0'
        compile 'com.google.firebase:firebase-appindexing:10.0.0'

        // Payments
        compile 'com.firebaseui:firebase-ui-database:0.4.0'
        compile 'com.braintreepayments.api:drop-in:3.+'
        compile 'com.loopj.android:android-async-http:1.4.9'
        compile 'com.google.android.gms:play-services-auth:10.2.0'
        compile 'com.facebook.android:facebook-android-sdk:4.+'
        compile 'com.google.android.gms:play-services-wallet:10.2.0'
        compile 'com.firebase:geofire-android:2.1.1'

    }

apply plugin: 'com.google.gms.google-services'

This is driving us crazy and I do not know why it does not receive a message. Again we are sending messages from the firebase notification console. We have a sent a message to the whole application and it still does nothing. Please help us. Thank you so much.


Try to remove Firebase.initializeApp(this) from onCreate . It's unneeded and may be the issue

onMessageRecieved not working when app is killed. · Issue #368 , But when app is killed I receive notification and after click on it- Extras == null. how to handle notification when app in kill in firebase android But the key takeaway is that your can never rely on FCM for communication. Firebase notifications behave differently depending on the foreground/background state of the receiving app. If you want foregrounded apps to receive notification messages or data messages, you’ll need to write code to handle the onMessageReceived callback. For an explanation of the difference between notification and data messages, see


As I can't comment yet:

I'm not pretty sure what "android-enabled" and "android-exported" tags mean and do in your service declaration in the manifest. Anyway it works for me even without these tags.

My MessagingService looks a little bit different:

The constructor is empty (not even calling super(...)). But I call

super.onMessageReceived(remoteMessage);

in my onMessageReceived method.

Try to add it to your onMessageReceived method :)

Edit: I use only 2 Permissions which are required to override the "do not disturb"-mode and to start a service when the device boot was completed.

My manifest looks like this (just FCM part):

<application>
<service android:name=".MyAppFirebaseService">
        <intent-filter>
            <action android:name="com.google.firebase.MESSAGING_EVENT" />
        </intent-filter>
</service>
<service android:name=".MyApp_FirebaseInstanceIdService">
        <intent-filter>
            <action android:name="com.google.firebase.INSTANCE_ID_EVENT" />
        </intent-filter>
</service>

My service looks like this:

public class MyAppFirebaseService extends FirebaseMessagingService {

    public MyAppFirebaseService() {

    }

    @Override
    public void onMessageReceived(RemoteMessage remoteMessage) {
        // ...
        super.onMessageReceived(remoteMessage);
        String title = "Title";
        String message = "Message";


        // Check if message contains a data payload.
        if (remoteMessage.getData().size() > 0) {
            title = remoteMessage.getData().get("title");
            message = remoteMessage.getData().get("body");
        }

        // Check if message contains a notification payload.
        if (remoteMessage.getNotification() != null) {
            title = remoteMessage.getNotification().getTitle();
            message = remoteMessage.getNotification().getBody();
        }
        //My method to display (create) the notification
        //Basically contains a notification(compat)builder
        displayNotifcation(title, message);

    }
}

Too see how the notification builder works just read this documentation: Android Developer Notification.Builder

Quick Start Example Cloud Messaging onMessageReceived never , The Firebase console always sends notification // messages. the foreground, onMessageReceived should be invoked, but it is never invoked. Firebase onMessageReceived not called when app in background (16) I'm working with Firebase and testing sending notifications to my app from my server while the app is in the background. The notification is sent successfully, it even appears on the notification centre of the device, but when the notification appears or even if I click on it, the onMessageReceived method inside my FCMessagingService is never called.


When sending a message you have to use some named channel, and your app should be subscribed on this channel using subscribeOnTopic("tome_topic").

In example, for channel "news", you will send messages to "/topics/news" channel, and your app have to be subscribed on this channel in order to receive messages:

FirebaseMessaging.getInstance().subscribeOnTopic("news");

Just add this into your onTokenRefresh() callback or call where you want.

If you don't want to receive messages from "news" channel, use FirebaseMessaging.getInstance().unsubscribeFromTopic("news");

Note, that when sending from your app server, you should use "/topics/news" for channel name, but in your app you use only "news".

And regarding to only one call of onTokenRefresh() - its ok that it isn't called each restart of app. The firebase client library stores token between restarts and does refresh only when it's needed.

Receive messages in an Android app, onMessageReceived is provided for most message types, with the following exceptions: Notification messages delivered when your app is in the background. In  When developers need to integrate push notifications in their Android apps, the first thing comes in mind is Firebase Notifications or Firebase Messaging. But when they integrate, there are few common issues which they stuck into. One of those common issues is that the applications doesn’t get push notifications.


Remove tools:node="replace" from your manifest file.

Receive messages in an iOS app, // this callback will not be fired till the user taps on the notification launching the application. // TODO: Handle data of notification // With swizzling disabled you must  In Android we received the PN and when is running then OnMessageReceived event fired and it's working but when my app is in background and when I clicked on Notification it will just open the App not fired the OnMessageReceived Event. Expected Behavior. When App is on background it should fire the OnMessageReceived event. Actual Behavior


I struggled with same issue 5days, code everything fine but firebase registrationnid not generating Notifications iam not receiving from firbase console, Finally i got solution

   <application
            android:allowBackup="true"
            android:icon="@mipmap/ic_launcher"
            android:label="@string/app_name"
            android:supportsRtl="true"
            android:theme="@style/AppTheme"
            tools:node="replace"
            tools:replace="android:supportsRtl">

Everything happend because of this Line inside Application tag      tools:node="replace"
Please remove this line it will work Perfectly sorry for my english.

Working easily with FCM push notifications in Android, In easy words, after I read how to work with Firebase Cloud Messaging' push entry, because in this way onMessageReceived method will never be called, and​  Remote Notifications with Firebase Cloud Messaging. 07/31/2018; 23 minutes to read +4; In this article. This walkthrough provides a step-by-step explanation of how to use Firebase Cloud Messaging to implement remote notifications (also called push notifications) in a Xamarin.Android application.


Firebase Notifications in Background & Foreground in Android, Create a new class that extends it and implement the onMessageReceived method. Then get the Notification object from the remoteMessage and  Las notificaciones de Firebase se comportan de diferente manera, según el estado de primer plano o segundo plano de la app que las recibe. Si quieres que las apps en primer plano reciban mensajes de notificación o mensajes de datos, deberás escribir código para administrar la devolución de llamada onMessageReceived.


FCM Firebase Push Notifications not Received using GameSparks , Pushing notifications with the Firebase console works. Log("Token Null"); } } void OnMessageReceived(object sender, MessageReceivedEventArgs Log("​Subscribed Task Fired"); // }); } public void OnDestroy() { Firebase. But with the app closed, I dont get push notifications unless I send from the Firebase console. After setting up FCM in Android application, you can use Firebase console to send notifications. When foregrounded application receives a notification, onMessageReceived method is invoked.


Notifications on Android, Sending a notification to your users can be very beneficial when it Getting everything fired up. To get everything started we need to get Firebase setup in our application. To do that, we first have to create a project in the Firebase console. and do some work or build a notification in onMessageReceived . OnMessageReceived is called from the main thread (via the "Firebase Services" mono behavior) which isn't executed while the app is in the background unless you unpause the application. If you want to customize the message you should do so by overriding the Android messaging service.