How to achieve this in Android? - 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.

Related

Can I make an iOS/Android app "ring", to force the user to respond to a push notification?

I have a food ordering app and I need to inform the restaurants of a new order. I have a Capacitor app which often runs in the background of tablets/phones of the restaurant. As a result, they sometimes miss an order.
In order to solve this, it would be great if I could ring the device as if an alarm goes off or if the device gets a call. Then they can swipe away the notification to stop it or something like that, to make sure they saw it. I would choose the sound myself so that it isn't obnoxious.
Is anything like that possible?
yes it's possible but,
you should know the following:
for Android:
1-create a foreground service to keep notification appears to the
restaurants, in this case the restaurant can not hide the
notification.
once the restaurant receive the notification just
sent an event to the foreground service to handle the action and the
data.
start the order activity from foreground service, once the
activity is created just play a sound.
for IOS,
it should be the same but i don't know how to create a foreground service in IOS.

Show notification icon on status bar with React Native when app is not running on Android

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.

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.

Foreground service android wear

I didn't find any documentation about that. Is it possible to create a foreground service on android wear? Usually the foreground state is related with an ongoing notification but it's not possible on wear so I'm a bit confused. Is there anyone has a foreground service on wear?
As per documentation:
"The system enforces a timeout period. If you are displaying an activity and user's don't interact with it, the device sleeps. When it wakes back up, the Wear home screen is displayed instead of your activity. If you need to show something persistent, create a notification in the context stream instead."
So, i believe it's possible to have a persistent UI (may be not an ongoing foreground notification but a card or a stack instead).
Hope it helps.

Does cancelling a Foreground Service's notification pull the service out of the foreground?

I understand that the newer Android APIs require you to start an ongoing notification when the foreground service is running to alert the user that something is running.
My users are asking for a way to override this default behavior and hide the notification anyway (understandably).
If I hold a reference to the notification and cancel it after I call startForeground(..), will Android pull the service out of the foreground?
No. There is unfortunately no way around this.

Categories

Resources