Android Notifications disappear after some time - android

Android notifications disappear after some time, without touching it to cancel. What could cause this kind of problem? The notification is started in a Service.
Is that possible that the low memory causes this kind of problem?

Make sure that there is no any other service or project module, which does the following call NotificationManager.cancelAll() to cancel all the notifications. It is always better to keep the notifications controller over Unique ID and cancel only the notifications which are related to that part, by this the code won't touch the notifications posted by other project parts.
NotificationManager documentation.

Related

Running specific code, while the app is killed or in background state

I am using react-native-firebase for the push notifications and it works fine. I am also using CallKeep for handling VoIP calls. I want to display an incoming call when the app gets a notification while it is killed or in background (ex. like WhatsApp).
Regarding to the documenation if a message is received "the device silently starts your application in a background state. At this point, your background handler" code is triggered. But this does not happen. The handler is trigger only if I tap the notification.
I've also added some code in AppDelegate.mm like mentioned in the description but it not works.
BTW: I am currently on iOS and don't know how the effect is on an Android device.
So how can I achieve this, or it is even possible ?
So I found the solution. The problem was that I used firebase console to send a notification which did not contain "ContentAvailable: true" property. When I send a notification using the C# sdk including "ContentAvailable = true" then the background handler is called, even if the app is in background or killed.

Silent notifications in foreground services

I have multiple apps that kind of work together to do the same job and they all belong to the same developer. Each app runs a long-running service in the background and keeps processing user's input. The problem is that those services cannot run in the background for a long time because Android system will kill them. So I want to use foreground services instead of background ones to prevent the system from killing them. However, I don't want to annoy the users with multiple different notifications in the notification drawer.
I found out that creating a notification without assigning a channel in Android O, will let the system start the foreground service without showing a notification. Something like the following:
Notification.Builder builder = new Notification.Builder(context);
builder.setContentTitle(......);
builder.setTicker(......);
builder.setContentText(......);
builder.setSmallIcon(......);
builder.setLargeIcon(......);
Notification notification = builder.build();
startForeground(111, notification);
So I was thinking of showing a notification by creating a notification with a channel from one app and create a notification without a channel for the other apps as I described earlier. In that case, the user will see one notification for all my apps.
That solution works well for me. But I am wondering if it is an unintended use of the notification in the foreground services. I am afraid that Google will suspend my apps for doing that!!
Do you guys know if it is okay to implement that solution?
Or is there any way to stack the notifications together in a group even though they are different apps?
My goal is just to make the notification less annoying to the user.
Also, I am aware of JobScheduler & JobIntentService solutions. But they don't do the job in my case because I want to keep the service running. Not like do one job and stop the service...
You can create notification channel with IMPORTANCE_LOW (https://developer.android.com/training/notify-user/channels#importance).
There shouldn't be sound.
Or you can also use setOnlyAlertOnce() (https://developer.android.com/training/notify-user/build-notification#Updating) and the sound will be only once.

Cancel notification without using Notification Manager

I have an application in which it receives the notification when fired from Backend. Now what I want to achieve is that the notification should disappear after 2 minutes if user has not clicked on it (even if my app is killed or background). I know that this can be achieved by using the Notification manager's setTimeoutAfter() but that will work only if am making my custom notification using Notifcation Manger.But i want to dismiss the Notification generated by System after 2 minutes.
Any kind of suggestion or help will be welcomed.
It is not possible to do that. The default system notification builder is pretty bare bones and will not handle it. The best you can do is set a delivery timeout so if the device was off it won't get the notification once it expires.
See https://firebase.google.com/docs/cloud-messaging/concept-options#when_to_use_platform_specific_keys (only works on Android and Web)

Android notification lifecycle

In my app I have notifications which can be showed when application is not running. When I open and close application, notifications disappear.
Is it normal situation? Is there any method to keep notifications?
Make sure that there is no any other service or project module, which does the following call NotificationManager.cancelAll() to cancel all the notifications. It is always better to keep the notifications controller over Unique ID and cancel only the notifications which are related to that part, by this the code won't touch the notifications posted by other project parts.
For more reference follow Notification Manager:
https://developer.android.com/reference/android/app/NotificationManager.html

How to achieve this in Android?

I am looking at Avast, Lookout for example and I am trying to understand the concept of the implementation. So it is more like asking for direction for me.
Persistent App icon in Notification bar.
Am I correct to say there are function NotificationManager is able to do it?
Scan virus during app installation, I am not interested in virus scanning but the triggering mechanism.
Some kind of Android service bind to the main app?
Main app that can be bring up in the Notification menu.
A main app that remain trigger action to the bind services?
So what do I need to read to understand? NoticationManager, Services and ??
In short, I want to load a icon in the notification bar that can bring up my app. There is a background service that perform specific task for a set interval.
Yep, NotificationManager and Notification can help you with that.
You just need to create the notification with flag FLAG_ONGOING_EVENT (to make it persistent). Even better if your service IS REALLY performing some long-running task, if so, you can start your service via Service.startForeground which needs some 'ongoing' notification for running (notification is required to notify the user that there is some work going now).
For triggering app install event, you can use BroadcastReceiver with filter by Intent.ACTION_PACKAGE_ADDED.

Categories

Resources