Open app upon receiving push-notification [duplicate] - android

This question already has answers here:
Open app on firebase notification received (FCM)
(4 answers)
Closed 5 years ago.
I'm developing a WebRTC app with React Native. I've got Firebase working, and I can receive notifications on my Android/iOS devices whilst in the background or foreground.
Is there any way of when I receive a push-notification to automatically open the app for me, without requiring the user input?
Thanks in advance.

If you are going for the scenario of an incoming call, it's not the same for both platforms.
For Android, you can start an activity responding to a push notification, but iOS doesn't allow that. You can either send a regular push notification the user might miss, or use CallKit and integrate it with your stuffs.
Unfortunately I don't know good libraries for React Native that can help you with that yet, so it might have to be done natively and bridged to your RN code.
Edit:
Android example - In your native code handling a notification, you can use context.startActivity(launchIntent); to launch your app with an incoming call screen.

Sorry to deviate a little from the code perspective.
But if you are looking forward for external triggers, I would recommend MacroDroid as a potential solution. There are numerous triggers including Notification reads, SMS etc., Macrodroid is available in Play store with trial version limited to five macros per user. Logical validations, loops and much more features to explore.

Related

IONIC/Capacitor: Bring Android app to foreground on trigger

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.

How do popular apps like WhatsApp and Instagram receive push notifications even while the app is closed

I am creating a native social app which includes features such as Direct Messages, Voice and Video Calls etc and I have been trying to find a way to be able to receive data payloads from Firebase Cloud Messaging containing values such that I create a custom notification based on the type values from the data payload eg for VOIP calls I’d like to set a remoteInput action to see if a person declines or accepts a call or for direct messages add a remoteInput action for a quick reply and so far I haven’t had any luck especially with background services not being allowed anymore ever since the release of Android 8.1. So I would like to know if there’s a workaround I’ve been missing or if it’s even possible and if it is how do these popular apps do it. Thank you in advance.
Its same as your mentioned, once after the release of 8.1 apps are now more strict in regarding the background running process. There are actually two insights I had received while developed some projects. 1) More the app is used by the user, the app is sort of whitelisted and can receive more notifications, i.e., the system actually tracks the frequency of app usage. 2) You have the possibility to ignore your app from battery optimization process hence more chance of background process to run.

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

Can an iOS or Android app interact with another apps interactive push notifications?

I'm looking to make an app for myself that will sleep until a push notification from another specific app comes through and then automatically accepts or declines the interactive push notification. Is it even possible to have an app that reacts to other apps push notifications? If it could react, then could it then interact with the notification?
I know that apps cant directly interact with the interfaces of others, but since this would be using push notifications I was hoping there would be something I could do. I cant find anything on this anywhere else or at least I don't know what to look for.
Not sure about IOS but in Android we could use to listen Broadcast to listen Broadscasts by system and other apps. But i think there has been some restrictions recently with Broadcast due to battery optimisation. Of-course you can achieve this with another app only if you know what broadcast they're triggering so you need to have some partnership with these other apps.
iOS:
I fairly doubt that it is possible on iOS with a straightforward API, but take a look at this post: https://stackoverflow.com/a/43523429/768567
Android:
For Android you could implement a NotificationListenerService: https://developer.android.com/reference/android/service/notification/NotificationListenerService
There is a repository on Github with some example code:
https://github.com/Chagall/notification-listener-service-example

iOS Swift 3: implementing chain of notifications emulating Android's AlarmManager

I'm implementing an app with an internal calendar, fetched from a remote web service. I want to send a local notification to the user when an event of interest is scheduled in the calendar, at a specific time chosen by him. Just like the iOS calendar app, when you can create an event and ask to be notified X hours/days before it happens. The main difference is that you can't create events: they are downloaded from a pre-populated remote calendar.
In Android I've solved the problem by using AlarmManager, while in iOS with Swift 3 the closest I've got to porting the same solution was via opportunistic background data fetch. The main difference between the two solutions is that background data fetch doesn't work when the app has been killed.
It would be really important for me that local notifications worked even when the app is killed. I think users expect apps notifications to work even when the app is closed, like it happens with WhatsApp or Facebook. I know that those notifications are triggered by someone writing something and therefore they are Push Notifications, but the average user just expects notifications to keep working even when the app is closed.
What would be the most elegant solution to "emulate" the behaviour of Android's AlarmManager in iOS?
Scheduling a bunch of notifications in advance hoping that the user will eventually open the app before all of them are dequeued looks a badly designed solution.
Also, delegating all the work to the server and push the notifications to the subscribed devices looks quite bad too as it requires much more work on the server side. Plus it requires a server which is able to awake itself to send push notifications, which is something that I don't have. I only have a simple webserver which answers to HTTP requests.
EDIT : The ideal solution I'm looking for isn't any of the previous 2 options, since I find them more like workarounds than actual elegant solutions to what I perceive being a fairly common problem. There has to be a third option...
In iOS there is no way to achieve this. Looking at the documentation of application(_:didReceiveRemoteNotification:fetchCompletionHandler:), it states that
the system does not automatically launch your app if the user has force-quit it. In that situation, the user must relaunch your app or restart the device before the system attempts to launch your app automatically again.
You can receive push notifications, but no code will be executed until the user launches your app. So unless you are sending remote push notifications from a server, you cannot set up new local notifications until the user opens your app.

Categories

Resources