Hello fellow programmers.
I have a problem and would appreciate any insights.
An app that I'm developing should receive notifications - silent and regular.
When the app is open or in background everything is good, I receive every notification in a "silent" way and if logic requires it I pop a local notification.
The problem is when app is closed (cleared from background), I need to get a silent notification but every notification is handled by the operating system and pops it for the user to see.
What should I do to handle the app closed case?
Thanks.
It's not default behavior but you could achieve this by using a dirty logic. In your receiver/service class [who generates notification], just check any activity of your required application is active or not. If your application is not in active state than don't generate the notification.
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 have the next doubt:
I am working on an app that needs to start a foreground service. I know that since Android O, you need to attach a notification to that foreground service. So far so good.
The question is: what happens if the user disables that notification from settings? I have been testing the app and everything seems to work, but I wanted to double check on internet and I couldn't find anything.
Should I force the user to have notifications enabled if he/she wants that feature (which needs the foreground service)?
Does anyone have some insights on it?
Yes, it is best practice to ask the user to enable notification services.
Nowadays most app does this exercise to show a notification to users. Even in some special manufacturer like MIUI it is compulsory to start notification service from setting. So many app shows prompt for same and on positive click they navigate the user to setting screen too
Customers can turn off push notifications at the app level. When that happens, we all know the the notification tray UI will not show up. But,
Does GCM/FCM (android) and APNS (iOS) continue to deliver notification to the customer's phone regardless ?
Specifically, on android & iOS, will I be able to execute some logic in the push event listener regardless of whether the user turned the push notifications on/off ?
In Android, when we disable push notifications, does the OS automatically unregister the app from GCM/FCM ?
Note:
I am NOT interested in background app refresh on iOS or background refresh through WorkManager on Android. I am NOT interested in iOS silent notifications or other kinds of Background Executions.
My question is specifically whether the code block is invoked (or not) when push notifications are turned off at app level (using the toggle).
I am not sure about the android, but in iOS this thing is possible.
You can do this but just keep in mind, that Background App Refresh is enable in device.
For more details, look into this link
https://www.urbanairship.com/blog/watch-list-ios-8-opt-in-changes
I hope you get your answer from above link
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 have just integrated services into my android app - I am also using startForeground because it's a critical app.
So, my question is - how do I get it to revert the user to the application when they have done a keyPress on the notification / service in their Notification Panel. I have looked everywhere for this and can't find it anywhere...There isn't much point in using services if they don't get directed back to the app onKeyPress so really need to get this working.
Any help is much appreciated.
Thanks
So, my question is - how do I get it to revert the user to the application when they have done a keyPress on the notification / service in their Notification Panel.
If the user clicks on the entry in the notification panel (via touchscreen or D-pad), the PendingIntent you supplied via setLatestEventInfo() will be executed. Use an appropriate PendingIntent to bring up the activity you seek. Here is a sample application demonstrating this.