GithubHelp home page GithubHelp logo

Comments (8)

argzdev avatar argzdev commented on June 20, 2024 1

Hi there, @CDAfonso. Thanks for reaching out. I tried testing our Firebase Messaging quickstart in Unity with version 6000.0.0f1, and version 11.9.0 of Firebase Messaging, so far it seems to work. I was able to receive a token, and receive the message on foreground, and notification on background when testing on an Android 12 emulator. I did notice that the Android 13 does not receive a notification but that's due to the post notification permission needed for Android 13 devices or higher.

You could also try and use our quickstart and see if there's any configuration difference that could be causing this issue. Let me know if this helps. Thanks!

from firebase-unity-sdk.

argzdev avatar argzdev commented on June 20, 2024 1

That's good to hear, @CDAfonso. Your AndroidManifest.xml looks alright. However, I see that there might be a misunderstanding of how our Firebase Messaging notifications work. So for context, in our documentations:

  1. When in the background, apps receive the notification payload in the notification tray, and only handle the data payload when the user taps on the notification.
  2. When in the foreground, your app receives a message object with both payloads available.

In this case, since your app is on foreground, the app will receive the message in the app, but will not display anything in your notification tray. This is intended, and we do this to give our developers the freedom what to do with the provided information. If you'd like to display this in your notification, you would need to craft your own logic to display this.

Update: I do think that this answers your question. I'll go ahead and close this thread now. Thanks!

from firebase-unity-sdk.

argzdev avatar argzdev commented on June 20, 2024 1

Hey @CDAfonso, since our documentations describes this behavior. You will need to add a logic to display your notification in the OnMessageReceived of Firebase Messaging.

First you need to register your MessageReceived callback when you initialize Firebase Messaging. You can refer to it here.

public void Start() {
  ...
  Firebase.Messaging.FirebaseMessaging.MessageReceived += OnMessageReceived;
}

Once that is done, you can then add your logic for showing notifications in the OnMessageReceived

public void OnMessageReceived(object sender, Firebase.Messaging.MessageReceivedEventArgs e) {
  // Show notification here
  UnityEngine.Debug.Log("From: " + e.Message.From);
  UnityEngine.Debug.Log("Message ID: " + e.Message.MessageId);
}

from firebase-unity-sdk.

CDAfonso avatar CDAfonso commented on June 20, 2024 1

Thanks @argzdev , but how to get the message title and content? Can't find it anywhere.

EDIT: Okay, i did it. I managed to make it work , so i can convert to local notifications:

   public void OnMessageReceived(object sender, Firebase.Messaging.MessageReceivedEventArgs e)
    {
        Debug.Log("Received a new message from: " + e.Message.From);
        Debug.Log("Message ID: " + e.Message.MessageId);
        Debug.Log("Notification Title: " + e.Message.Notification.Title);
        Debug.Log("Notification Body: " + e.Message.Notification.Body);       
    }

Thank you @argzdev , wish you the best 🙏

from firebase-unity-sdk.

google-oss-bot avatar google-oss-bot commented on June 20, 2024

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

from firebase-unity-sdk.

CDAfonso avatar CDAfonso commented on June 20, 2024

Thank you @argzdev!

After more testing, i can affirm that i am getting notifications on android, but ONLY WHEN APP IS BACKGROUND.
If the app is in foreground, i can see message received on the android logcat, but it doesn't show on tray (Tried with 2 devices).

This 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.emequatro.mediatypo" android:versionCode="1" android:versionName="1.0"> <uses-permission android:name="android.permission.POST_NOTIFICATIONS"/> <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.MessagingUnityPlayerActivity" android:configChanges="fontScale|keyboard|keyboardHidden|locale|mnc|mcc|navigation|orientation|screenLayout|screenSize|smallestScreenSize|uiMode|touchscreen"> <intent-filter> <action android:name="android.intent.action.MAIN" /> <category android:name="android.intent.category.LAUNCHER" /> </intent-filter> <meta-data android:name="unityplayer.UnityActivity" android:value="true" /> </activity> <service android:name="com.google.firebase.messaging.MessageForwardingService" android:permission="android.permission.BIND_JOB_SERVICE" android:exported="false"></service> <meta-data android:name="com.google.firebase.messaging.default_notification_icon" android:resource="@drawable/notification_icon" /> </application> </manifest>

from firebase-unity-sdk.

CDAfonso avatar CDAfonso commented on June 20, 2024

Thank you, @argzdev for your precious help.
In my past projects, it worked without any aditional code, showing notifications even if the app is in foreground.
I've read that this changed in the latest sdk's... so how do we deal with this now in Unity?

Thank you so much.

from firebase-unity-sdk.

argzdev avatar argzdev commented on June 20, 2024

Awesome! Great to hear that it's working.

from firebase-unity-sdk.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.