4

I'm testing Firebase cloud messaging. I have the following class

public class MyFirebaseMessagingService extends FirebaseMessagingService {
    @Override
    public void onMessageReceived(RemoteMessage remoteMessage) {
        Log.d("From: ", "From: " + remoteMessage.getFrom());
    }
}

My app does generate a token for my device, and I am testing this from the Firebase console. When I send a test message from the Firebase console I get the following messages

03-03 18:16:34.638 12091-12871/com.rev.future D/FA: Logging event (FE): notification_receive(_nr), ..............
03-03 18:16:34.672 12091-12871/com.rev.future D/FA: Logging event (FE): notification_foreground(_nf), ...............
03-03 18:16:34.690 12091-12871/com.rev.future D/FA: Connected to remote service
03-03 18:32:24.462 12091-15272/com.rev.future D/FA: Logging event (FE): user_engagement(_e),..........
03-03 18:32:24.534 12091-15272/com.rev.future D/FA: Connected to remote service

But I never see the message "From: " which makes me believe that the onMessageReceived is not being called

Why is onMessageReceived not being called when I send a message to my device?

EDIT: I am also adding 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.rev.future">

    <uses-permission android:name="android.permission.SEND_SMS" />
    <uses-permission android:name="android.permission.READ_SMS" />
    <uses-permission android:name="android.permission.WRITE_SMS" />
    <uses-permission android:name="android.permission.RECEIVE_SMS" />
    <uses-permission android:name="android.permission.RECEIVE_MMS" />
    <uses-permission android:name="android.permission.READ_PHONE_STATE" />
    <uses-permission android:name="android.provider.Telephony.SMS_RECEIVED" />
    <uses-permission android:name="android.permission.WAKE_LOCK" />
    <uses-permission android:name="android.permission.INTERNET" />
    <uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
    <uses-permission android:name="android.permission.CHANGE_WIFI_STATE" />
    <uses-permission android:name="android.permission.CHANGE_NETWORK_STATE" />
    <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
    <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
    <uses-permission android:name="android.permission.WRITE_SETTINGS" />

    <application
        android:allowBackup="true"
        android:debuggable="true"
        android:icon="@mipmap/ic_launcher"
        android:label="@string/app_name"
        android:roundIcon="@mipmap/ic_launcher_round"
        android:supportsRtl="true"
        android:theme="@style/AppTheme"
        tools:ignore="HardcodedDebugMode">
        <activity android:name=".MainActivity">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

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

        <!-- BroadcastReceiver that listens for incoming SMS messages -->
        <receiver
            android:name=".SmsReceiver"
            android:permission="android.permission.BROADCAST_SMS">
            <intent-filter>
                <action android:name="android.provider.Telephony.SMS_DELIVER" />
            </intent-filter>
        </receiver>

        <!-- BroadcastReceiver that listens for incoming MMS messages -->
        <receiver
            android:name=".MmsReceiver"
            android:permission="android.permission.BROADCAST_WAP_PUSH">
            <intent-filter>
                <action android:name="android.provider.Telephony.WAP_PUSH_DELIVER" />

                <data android:mimeType="application/vnd.wap.mms-message" />
            </intent-filter>
        </receiver>

        <!-- Activity that allows the user to send new SMS/MMS messages -->
        <activity android:name=".ComposeSmsActivity">
            <intent-filter>
                <action android:name="android.intent.action.SEND" />
                <action android:name="android.intent.action.SENDTO" />

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

                <data android:scheme="sms" />
                <data android:scheme="smsto" />
                <data android:scheme="mms" />
                <data android:scheme="mmsto" />
            </intent-filter>
        </activity>

        <!-- Service that delivers messages from the phone "quick response" -->
        <service
            android:name=".HeadlessSmsSendService"
            android:exported="true"
            android:permission="android.permission.SEND_RESPOND_VIA_MESSAGE">
            <intent-filter>
                <action android:name="android.intent.action.RESPOND_VIA_MESSAGE" />

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

                <data android:scheme="sms" />
                <data android:scheme="smsto" />
                <data android:scheme="mms" />
                <data android:scheme="mmsto" />
            </intent-filter>
        </service>

        <activity android:name=".PermissionActivity" />

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

</manifest>
david
  • 997
  • 3
  • 14
  • 34
  • Have you declared `MyFirebaseMessagingService` in your manifest as [described in the setup instructions](https://firebase.google.com/docs/cloud-messaging/android/client#manifest)? – Bob Snyder Mar 04 '18 at 02:09
  • Yes I have, I also added my manifest to the question – david Mar 04 '18 at 02:35

1 Answers1

1

The declaration of the messaging service in the manifest is missing the intent filter:

<service
    android:name=".MyFirebaseMessagingService">
    <intent-filter>
        <action android:name="com.google.firebase.MESSAGING_EVENT"/>
    </intent-filter>
</service>

For reference, see the setup instructions.

Bob Snyder
  • 37,759
  • 6
  • 111
  • 158
  • I have updated my manifest. This is what I have now https://pastebin.com/5eH11sbx But when I run my app I get "Error:Execution failed for task ':app:processDebugManifest'. > Manifest merger failed with multiple errors, see logs" and when I check the merged tab I get these errors "Merging Errors: Error: Element service#com.rev.future.MyFirebaseMessagingService at AndroidManifest.xml:102:9-107:19 duplicated with element declared at AndroidManifest.xml:98:9-101:47 app main manifest (this file), line 101 Error: Validation failed, exiting app main manifest (this file)" – david Mar 04 '18 at 02:50
  • You have the service declared twice in the manifest. Delete the original declaration and leave the one posted in this answer. – Bob Snyder Mar 04 '18 at 02:54