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
Related
We have a pretty common usecase with our (via Capacitor) Android generated app:
Once it receives a message via e.g. a Websocket (or third party apps like OneSignal, Firebase etc) we want to bring the app to the foreground in case the user is currently interacting with other apps (like Skype, Whatsapp etc). The reason is that we have implemented an "Alarm" scenario and if an alarm comes in, the app should come to front and show what's going on. Simple push notifications won't do the job here.
So we researched on the topic but as we're not native Android devs, we don't understand the full picture clearly.
e.g. Android bring app to foreground on Firebase notification suggests that via FLAG_ACTIVITY_REORDER_TO_FRONT it is possible to bring an app from the background to foreground.
The question is how is this going to be implemented in a hybrid app scenario (like with Cordova/IONIC/Capacitor).
In our app we are pretty far to listen to API signals via Websocket. Once an alarm is received we are able to send a signal to the App via Websocket so we can do pretty much anything. We could for example redirect the signal from the webapp back to the app container.
The question now is how can this scenario be solved either via Websocket or Firebase (FCM) and is it possible to solve it straight through the IONIC architecture?
In a cordova/ionic hybrid app I would use the cordova background mode plugin and the window_system_alert permission plugin. Those two are what I'm using and its working like a charm.
The steps I'd follow:
The first one was to include the force-start to the notification body
The second one was to give permissions to the app to be drawn over other apps. I managed to to this using this plugin: https://github.com/wryel/cordova-plugin-system-alert-window-permission. It requests the SYSTEM_ALERT_WINDOW permission.
The last one is to install the background-mode plugin (https://github.com/katzer/cordova-plugin-background-mode) and whenever you receive a notification you wake up the terminal and show your app in foreground (enable -> unlock -> moveToForeground).
Please, let me know if I misunderstood something and I can change my answer.
My understanding is to receive the data from push notifications while the app is in the background or not running, one need a service which will put the data somewhere where the app can get at them when it starts up or goes to the foreground. It appears that a common solution is to put the data into the app's Extras.
There are plenty of references for Java but my google-fu fails to find an implementation guide for Delphi.
Also useful would be information on how to "Stack" the notifications into a single notification.
I imagine one could write a single service which is triggered each time a notification arrives, and which then a) puts the data portion of the notification into the app's extras, and b) replaces the notification with a single stacked notification.
My question is "how does one write this service" - some template code would help, and tutorials or reference documents would be great.
FWIW this is for an app with a chat like feature where one doesn't want any notifications to get lost.
One thing at a time... here's a guide for implementing a service on Android.
Full disclosure: I've no idea how effective or useful it is or how complete (or otherwise) Delphi capabilities for Android services are since I use Oxygene for Android development (also Object Pascal but works very differently than Delphi, enabling me to make use of all those Java references).
The rest of your question seems more related to specific business/application requirements than a programming/technical problem, but if you run into specific issues you should consider asking questions about those separately.
I'm developing viber like application using the ionic framework.
I want my app to be able to receive calls even when its on the background, just like whatsapp, the incoming call screen will pop up even if whatsapp is on the background or even when there is no instance of it at all.
I wasn't able to find anything about it.
I'm afraid there's no other way to achive this, then using Google Cloud Messaging (GCM). Although there may be other services that do the same.
When using GCM, your app will be notified with a notification even if it is not running.
But be careful! As your using Ionic, you will most likely rely on a cordova plugin to receive the notifications that are pushed to your device via GCM.
It depends on the chosen plugin how it handles the incoming notification.
I want to invoke the WL.Client.Push.subscribe(alias, options) or WL.Client.Push.unsubscribe (alias, options) through the Show notifications in Android and Include in iOS. Instead of adding a Subscribe/Unsubscribe handle in my app,i want it to be handled through the OS's controls.
Those things are not the same.
Subscribing/unsubscribing to push notifications is one thing. Controlling how the notifications are displayed/displayed at all in the device is another.
The answer is then, IMO: No, you can't use those features to control whether your application (device, rather) is subscribed or unsubscribed from push notifications.
By subscribing/unsubscribing, you manage the server state regarding the notifications.
That said, in your application you should be able to query for the state of these controls for the app (in iOS that should be UIApplication > enabledRemoteNotificationTypes), and based on the result to subscribe or unsubscribe. To do that, you'll need to write a Cordova plug-in. I don't know how well that was supported back in Worklight 5.0.5.x, that is a pretty old version of Worklight.
You should tell your customer to upgrade. :-)
I have implemented a push notifications plugin for PhoneGap Build, waited for it for so long
https://build.phonegap.com/blog/introducing-genericpush-plugin
However I'm having issues with the Android app not running in the background. Push notifications are not received when I close the app. Everything is fine when the app is running. Has anyone tried it with Android? Are there any fixes that need to be done?
Thanks!
It's not something related to the GenericPush plugin itself.
It's something related to the way Android manages apps. If your user manually closes the app, it means that he doesn't want to receive messages anymore. This is why even the GCM BroadcastReceiver is stopped and the device doesn't receive the notifications.
Here's some useful links:
Android GCM google groups
Similar question, related only to Android (native)