As the title says, I'm scheduling some notifications for android on unity but I would like them to not appear if the app is open (only foreground and closed). I didn't find any information on the documentation. I guess I can cancel them right before the fire time, but is there any other option?
Related
I have a situation on my React Native app, where user can start a timer and isRunning and startTime states are stored in the app so that it can display current running time when the app is in foreground even though the user quits the application at some point and opens it again.
Is there a way to show notification icon on status bar when the timer is running, but user has quit the application to indicate that the timer is currently "running" (actually it is not doing any operations on background) on background?
I have encountered some apps that display a silent notification that is not directly closable after I have quit the app, but I haven't seen a situation where status bar notification is present (together with notification) until some condition is met after the app is quit by the user.
Is there a way to achieve this? I am using react-native-push-notification and Firebase to push notifications in my app overall.
React-Native manages only Active and Background/Inactive/Foreground state. When user kill the app. JS engine shuts down.
All you can use is Local Notification and Scheduled Notification. I also have one app in which user set a reminder time. And notification invoke at that specified time.
Using Firebase I guess you need to call api after some specific interval for push notification from server side.
I am not an expert in background services or android development but here is my thought... I believe you could dig in and write some java android code for a background unstoppable service (persistent on app close or background states). You can do this by creating a bridge and using native modules to manage your background services. I came across a great resource on medium that details the process of creating a background service, a broadcast receiver and maintaining Headless instance even when the app is closed or the device restarts.Hope that helps you achieve your goal.
Edit
This ready made package will help you with better. Check it out. You actually don't have to write native android java code at all.
I was looking into ways to send push notifications to a native app and reading the expo documentation, I got confused by two bits of information that seem to contradict each other.
Notifications will appear in the system notification tray as you've
come to expect, and tapping them will open/foreground the app.
(source: https://docs.expo.io/versions/latest/guides/push-notifications)
But in the section 'why not expo' it states :
Expo apps don't support background code execution (running code when
the app is not foregrounded or the device is sleeping). This means you
cannot use background geolocation, play audio in the background,
handle push notifications in the background, and more.
(source: https://docs.expo.io/versions/latest/introduction/why-not-expo)
That seems contradictory since 'foregrounding' or 'opening' an app implies that it was running in the background how I see it.
In the end I would like to change the notification badge of an app icon with this, but given this info it's not clear to me if this is possible ? In IOS and Android ?
Indeed foregrounding the app sounds as if the app was actively running in the background and could therefore run code, but as the documentation states, this is not currently feasible with Expo alone. This entails that changing the badge count while the app is in background cannot be done.
On the other hand, when the app is in foreground or the notification is being open, this becomes feasible according to this table in the documentation.
Setting an arbitrary badge count on iOS can be done with Notifications.setBadgeNumberAsync(number), whereas for Android the only option available is to make the sent push notifications count towards the badge count for a given channel.
remove notification badge count for android - Notifications.dismissAllNotificationsAsync()
expo dismissAllNotificationAsync
Integrated Applozic in android app, and also tried sample app,
notification for any message only works if app is open or in background.
It does not work if we close/kill application (remove from background).
All the setup for firebase key etc is done exactly as given in doc.
And it is correct I think as notification works if app is open.
I think service which works to show notification stops when we close app, How to keep it running?
Thanks
I am trying to implement a functionality wherein users get notification messages even when the app is not running (neither in foreground nor in background). Companies like Amazon do send notifications and they show up in the notification tray - when tapped, the app opens or whatever intent the message carried with it.
I have been able to implement notification handling when the app is in foreground and background... but when the app is not running, there are no notification messages received at all!
From what I searched around, I think there needs to be a Service running in the background that keeps listening to notification messages - because a service is destroyed when the app is closed. Am I going in the right direction?
Can someone point me to some code that implements or highlights the same.
FIXED... actually.. the problem was MIUI.. Its security app by default disabled autostart for apps.. which blocks notifications from being shown in the system tray when the app is not running.
References:-
http://en.miui.com/thread-37783-1-1.html
https://github.com/firebase/quickstart-android/issues/89#issuecomment-233558184
I you have to see the implementation of FCM for android from https://firebase.google.com/docs/cloud-messaging/
I shows complete understanding of instant notification.
I am using the local notification plugin for Cordova.
When the app goes to the background on Android and when the app comes to the foreground the notifications are hidden from the notification area.
I can still get them from getById.
How can I get a notification that stays until I cancel or clear them?
Or is this Android specific behaviour?
You should check out the backgroundmode plugin to be able to control it (and the notifications) when it goes to the background. Also from the same author, a good notification plugin.
"Cordova plugin to prevent the app from going to sleep while in background.
Most mobile operating systems are multitasking capable, but most apps dont need to run while in background and not present for the user. Therefore they pause the app in background mode and resume the app before switching to foreground mode. The system keeps all network connections open while in background, but does not deliver the data until the app resumes."