Comments (8)
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.
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:
- 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.
- 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.
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.
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.
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.
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.
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.
Awesome! Great to hear that it's working.
from firebase-unity-sdk.
Related Issues (20)
- Firebase HOT 3
- [Question] INVALID_APP_ID error on Android HOT 8
- [Question] i don't know why please check URL HOT 4
- [Bug] DllNotFoundException: FirebaseCppApp-11_6_0 in Windows 10 HOT 8
- [Bug] Persistent connection error thrown when using Unity 2022 on Mac HOT 3
- [Bug] Problem with dependency resolution for Android and Unity 6000.0.1 HOT 12
- [Bug] Invalid mainTemplate.gradle for Unity 6000.0 HOT 7
- [Bug] Crash [libFirebaseCppApp-12_0_0.so] firebase::Mutex::Acquire() HOT 5
- [Question] Firebase - NoClassDefFoundError at startup HOT 6
- [Bug] Processing Libraries from Forced Resolution popup won't disappear HOT 3
- [Bug] Gradle build fails after upgrading to Firebase 12.0.0 HOT 9
- [Bug] Firebase wants to use your confidential in keychain after add keychain-access-group. HOT 8
- [FR]: Why require google-services.json, if possible without it? HOT 1
- [Bug] Crash in firebase::auth::Env HOT 3
- [Bug] Apple Sign In with Android can sometimes freeze the app HOT 4
- [Bug] "Please fix your bundle id window" - annoyingly keeps appearing! HOT 3
- [Question] Firebase analytics LogEvent do not work in unity lifecycle methods,but buttons work as normal
- [Bug] NullReferenceException when we call GoOffline from Unity's OnApplicationQuit() HOT 5
- Auth not working in Unity editor HOT 6
- [Bug] Error caught by debugger on each recompile when in play mode HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from firebase-unity-sdk.