Firebase C++ Cloud Messaging background issues - android

So, I have a Firebase C++ SDK integrated into my Android app and I'm having certain troubles handling my push notifications when my app is in the background.
The thing is that for some reason OnMessage method of messaging::Listener class never gets called when I launch my app through a notification, which is weird, because in a situation when my app is already in foreground when the device gets a notification - OnMessage gets called perfectly fine and I get all the info about the received notification.
AFAIK OnMessage should also be called by the Firebase sdk when a user launches/resumes the app through the notification from the notification bar so that the app could get the payload, but this doesn't happen for me for some reason and I don't know where to look (nothing in adb log, no errors, etc).

Turned out that Firebase Cloud Messaging C++ SDK for Android requires some additional coding that is not described in the integration documentation, but, can be found in the sample app on Github (https://github.com/firebase/quickstart-cpp/blob/master/messaging/testapp/src/android/java/com/google/firebase/example/TestappNativeActivity.java#L35).
When I added the missing code in onNewIntent method - FCM OnMessage callback started to work as expected;

Related

Why do Android Push Notifications call Application create and trigger AppStartup

I have noticed that when I send a push notification (Firebase Messaging Service) to my device my Application object is created. This is without clicking on the notification. Simply the act of viewing the notification creates the application. Further, it also starts the Jetpack AppStartup library. I want to be able to use AppStartup and application create. But I don't want to launch that code when a push notification occurs.
Why does Android do this? Is this part of all android notification, or is it a feature of the third-party push notification sdk I am using? And is there a way in Application.create and AppStartup to distinguish a normal app launch from a push notification triggered launch?
Again, I'm not talking about the user clicking on the notification (and launching the app because of a deeplink). I'm talking about just looking at the notification in the notification dropdown.
Why does Android do this?
Android is starting your app process to run code in your app. Creating an Application instance and calling onCreate() will be part of that, as will creating any ContentProvider objects. IIRC, Jetpack Startup uses a ContentProvider to get control early in your process, though I am not 100% certain of that.
The reason why Android is starting your app process is because your app is causing the Notification to be displayed — specifically, Firebase Cloud Messaging is doing that. If I remember the protocol correctly, Play Services is sending a broadcast Intent that Firebase Cloud Messaging in your app will respond to, and part of that code will be displaying the Notification.
And is there a way in Application.create and AppStartup to distinguish a normal app launch from a push notification triggered launch?
onCreate() of an Application subclass has no means of knowing what specifically caused the process to be created, as there can be many possible reasons. If by "AppStartup" you mean Jetpack Startup, I do not recall it having any options here, but I have not spent much time with its API.

Remove Firebase Notifications from tray (Android, Unity SDK)

I successfully implemented the Firebase Unity SDK for notifications (sent by a cloud function). My understanding of notifications is that it should not end up in the notification tray at all if the app is open and takes it (it has data and notification portion), however in fact all notifications pile up in the tray. I managed to provide a CollapseKey and according message tag to at least have just the latest one show up there, however as long as the app is in the foreground (also when device goes to sleep) there is actually no point in notifying via tray.
So what I would like to do is to actively remove any notification on app start or recovery from pausing/sleeping. Is that somehow possible? I haven't found any API within the Unity SDK.
Thanks, habitoti
It looks like this is an issue on Android proper as well, and there's already a good Stack Overflow post on it. If you're unable or uncomfortable with writing a native Android plugin (I actually create an Android messaging plugin in this article as an example), I think I have a pure Unity solution.
First, you will need to pull in the Mobile Notifications package (the documentation is for a preview, but it looks like 1.0.3 is stable).
Then you should be able to call CancellAllNotifications as listed here. It's a static function, so all the code you should need is:
AndroidNotificationCenter.CancellAllNotifications();
LMK if that works for you!
--Patrick

cordova-plugin-firebase unregister to push notification

I am using the cordova-plugin-firebase plugin to receive push notifications from firebase to my iOS and Android devices.
What I want is, that the user can disable or enable the push notificications through the app.
Everything works fine, except for the unregister part.
I am using the window.FirebasePlugin.unregister(); function.
After that, my iOS devices won't receive messages anymore, which is good.
But after trying to register again, with the window.FirebasePlugin.getToken(); function, my iOS device still won't get any messages.
So on iOS I can't register again. On Android however, the unregister function won't work at all. I still get all notifications send from firebase.
What am I doing wrong ? How can I register and unregister?

Get push notification payload when opening app, Android Titanium Appcelerator

I have activated push notifications in my application and I have done all the settings with Google and Apple to be able to send from the Appcelerator Dashboard.
I can receive notifications on both Android and iOS without any problems.
In iOS, when i click the notification from the notification center, the application opens and the callback function of Ti.Network.registerForPushNotifications is executed automatically.
The problem is that in Android, the function assigned to the callback event of the cloudPush module is not executed, I understand that it will be because when opening the application the listener is not yet created.
If I receive the notification when the application is open the callback function runs smoothly.
Reading in documentation of Android seems to me to understand that the notification is included in the extras of the intent when opening the application, but I am not clear what extra is, since in Appcelerator I do not find any function to obtain all the extras.
Someone could give me an idea of ​​how to get the payload, whether or not when I click the notification the app is in the background, as if it is totally closed?
Thanks in advance.

Ionic android push notification works only in background

I'm building an Ionic App which uses push notifications. I followed the documentation from here . I can register, I see the token is registered OK, but when I send notifications from ionic, I receive them only if the app is in background. If the app is running, I get no notification . The event cloud:push:notification is not triggered.
Any ideas?
Thanks!
Make sure to use the ionic-cloud library for interfacing with Ionic.io. The event you mentioned is not triggered by the deprecated ionic-platform-web-clinet
http://docs.ionic.io/migration.html#push`

Categories

Resources