firebase / firebase-android-sdk

Firebase Android SDK
https://firebase.google.com
Apache License 2.0
2.23k stars 565 forks source link

onMessageReceived() is not called in newest Android #6051

Open super0610 opened 1 week ago

super0610 commented 1 week ago

[READ] Step 1: Are you in the right place?

Issues filed here should be about bugs in the code in this repository. If you have a general question, need help debugging, or fall into some other category use one of these other channels:

[REQUIRED] Step 2: Describe your environment

[REQUIRED] Step 3: Describe the problem

Steps to reproduce:

What happened? How can we make the problem occur? MyFirebaseMessagingService class is declared in Manifest, app receive Token from onNewToken() function. However, onMessageReceived is never called.

Relevant Code:

// TODO(you): code here to reproduce the problem
 @Override
    public void onMessageReceived(@NonNull RemoteMessage message) {
        super.onMessageReceived(message);

        LogUtil.e( "From: " + message.getFrom());
        if (message.getData().size() > 0) {
            for (String key : message.getData().keySet()) {
                LogUtil.e("Key: " + key);
                LogUtil.e("Value: " + message.getData().get(key));
            }
        }

        if (message.getNotification() != null) {

            LogUtil.e( "Message Notification Title: " + message.getNotification().getTitle() +
                    "   Body:" + message.getNotification().getBody());
        }
        sendNotification("Received Push");
    }

And this is manifest

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

    <application
        android:name="com.sollyfaks.tehillim.MyApp"
        android:allowBackup="false"
        android:icon="@mipmap/ic_launcher"
        android:label="@string/app_name"
        android:roundIcon="@mipmap/ic_launcher_round"
        android:supportsRtl="true"
        android:theme="@style/AppTheme.NoActionBar"
        android:usesCleartextTraffic="true"
        tools:replace="android:allowBackup"
        >

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

   </application>

I gave Notifications permission manually

Also tried to send test notification like document.
https://firebase.google.com/docs/cloud-messaging/android/first-message#send_a_test_notification_message

Important thing is old phones (Galaxy S8, android version 9) works, but my new phone (S21, android version 14) didn't work.
App is targeting Android 33
google-oss-bot commented 1 week ago

I couldn't figure out how to label this issue, so I've labeled it for a human to triage. Hang tight.

lehcar09 commented 1 week ago

Hi @super0610, thank you for reaching out. I tried reproducing the issue with an Android Device version 14, however, I did not encounter an issue and the onMessageReceived is triggered accordingly.

Can you clarify what you mean by:

I gave Notifications permission manually

It's possible that the message is not delivered, so the onMessageReceived is not delivered. The are several factors that could affect the delivery of message on the device. You can check this blog post for more details.

In addition to that, just to note, onMessageReceived is not called when you send 'notification only' and the app is in background. You can check this documentation for more information about handling messages.

We're you able to reproduce the issue on another Android 14 device?