Skip to content

[Bug] Using Firebase Message in Unity onMessageReceived not called when app in background or Killed #1061

@muhammadali514

Description

@muhammadali514

[REQUIRED] Please fill in the following fields:

  • Unity editor version: 2020.2.7f1
  • Firebase Unity SDK version: 7.2.0
  • Source you installed the SDK: FirebaseMessaging.unitypackage (.unitypackage or Unity Package Manager)
  • Problematic Firebase Component: FirebaseMessaging (Auth, Database, etc.)
  • Other Firebase Components in use: _____ (Auth, Database, etc.)
  • Additional SDKs you are using: _____ (Facebook, AdMob, etc.)
  • Platform you are using the Unity editor on: Windows _____ (Mac, Windows, or Linux)
  • Platform you are targeting: Android _____ (iOS, Android, and/or desktop)
  • Scripting Runtime: IL2CPP(Mono, and/or IL2CPP)

[REQUIRED] Please describe the issue here:

Firebase onMessageReceived not called when app in background or killed in unity project using Unity "2020.2.7f1" Firebase message "sdk7.2.0"

Notifications are working and getting data while app is open if app is killed or paused no data shows up. Stuck in it from 4 days and more

Steps to reproduce:

Have you been able to reproduce this issue with just the Firebase Unity quickstarts (this GitHub project)?
What's the issue repro rate? (eg 100%, 1/5 etc)

What happened? How can we make the problem occur?
This could be a description, log/console output, etc.

If you have a downloadable sample project that reproduces the bug you're reporting, you will
likely receive a faster response on your issue.

Relevant Code:

public void Start() 
    {
      Firebase.Messaging.FirebaseMessaging.TokenReceived += OnTokenReceived;
      Firebase.Messaging.FirebaseMessaging.MessageReceived += OnMessageReceived;
    }
    public void OnTokenReceived(object sender, Firebase.Messaging.TokenReceivedEventArgs token) 
    {
        Firebase.Messaging.FirebaseMessaging.SubscribeAsync("/topics/com.alpha.romeo");
        
    }
    public void OnMessageReceived(object sender, Firebase.Messaging.MessageReceivedEventArgs e) 
    {
            string title = e.Message.Data["title"];
            string url = e.Message.Data["app_url"];
            string short_disc = e.Message.Data["short_desc"];
            string icon = e.Message.Data["icon"];
            string feature = e.Message.Data["feature"];

            //e.Message.Data.TryGetValue("title",out title);
            //e.Message.Data.TryGetValue("app_url",out url);
            //e.Message.Data.TryGetValue("short_desc",out short_disc);
            //e.Message.Data.TryGetValue("icon",out icon);
            //e.Message.Data.TryGetValue("feature",out feature);
            
            Debug.Log("Alii Valuess  "+title);
            Debug.Log("Alii Valuess  "+url);
            Debug.Log("Alii Valuess  "+short_disc);
            Debug.Log("Alii Valuess  "+icon);
            Debug.Log("Alii Values    "+feature);

            RateUs(title,url,short_disc,icon,feature);
             
    }
<?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.alpha.romeo" android:versionCode="1" android:versionName="1.0">
  <uses-permission android:name="com.google.android.c2dm.permission.RECEIVE"/>
  <uses-permission android:name="android.permission.WAKE_LOCK"/>
    <application android:label="@string/app_name" android:icon="@drawable/app_icon">
    <!-- The MessagingUnityPlayerActivity is a class that extends
         UnityPlayerActivity to work around a known issue when receiving
         notification data payloads in the background. -->
    <activity android:name="com.google.firebase_workaround.MessagingUnityPlayerActivityWorkaround" android:configChanges="fontScale|keyboard|keyboardHidden|locale|mnc|mcc|navigation|orientation|screenLayout|screenSize|smallestScreenSize|uiMode|touchscreen">
      <meta-data android:name="unityplayer.UnityActivity" android:value="true" />
      <intent-filter>
      <action android:name="android.intent.action.MAIN" />
        <category android:name="android.intent.category.LAUNCHER" />
      </intent-filter>
    </activity>
    <service android:name="com.google.firebase.messaging.MessageForwardingService" android:permission="android.permission.BIND_JOB_SERVICE" android:exported="false">
    <intent-filter>
        <category android:name="android.intent.category.LEANBACK_LAUNCHER"/>
        <category android:name="com.google.firebase.MESSAGING_EVENT" />
      </intent-filter></service>
  </application>
</manifest>

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions