How to hide app in notification bar [duplicate] - android

This question already has answers here:
How to put media controller button on notification bar?
(4 answers)
Closed 5 years ago.
I want to hide my app in Notification Bar such as the music player application. When the user presses a button the app should close and display as ongoing in the Notification Bar.
Also how safe is System.exit()?

What you are asking for is actually called a Foreground Service.
You can easily find all the documentation about Service and Foreground Service on developer.android.com.
As for quick reference :
Service : Service are android application components which has no user interface and is usually used to carry on background operations. You can read more about android services here.
Foreground Service : These are the just the "subset" of services which perform an operation of which user is continously aware of. These service tend to live for longer duration. You can read more about service here. Since the user has to be continously aware of this service, to this in android, the OS puts a notification related to this service.
So, Now you must be able to see that to "hide app in notification bar", you will have to create a service (so that it runs in the backgournd, and is kind of hidden from what user can see) and mark it as a Foreground Service (so that there is a notification bar associated with the service).

Related

Endless background processes without a service and any UI shown

I'm running the Slack app on an Android 11 device. If the app is placed in the background by tapping on the device's home button and a Slack chat message arrives, it displays a notification on the Android notification bar. If you tap on the notification icon to open the notification and then tap on the message, the notification is removed.
What puzzles me is whether an app like Slack even uses a foreground service when receiving chat messages. From my experiencee, to have a continously running background service when no UI is shown, you must display a notification icon on Android's notification bar to indicate to the user that the app is running a background service. While this is considered a background service, it is in fact referred to as a foreground service.
But Slack does not display an icon on the Notification bar to indicate any foreground service. So if it's not using a foreground service but can receive messages while the UI is not shown and post a notification, how is this being done? Has something changed in Android that you don't need a foreground service in order to run a long running process in the background?
The only possible explanation I can think of is that instead of a service, a class that inherits from Application is used and the process for receiving messages is done within a coroutine that is launched from this class and remains active as long as the app remains alive. But if that is true, it means that apps CAN run endless background processes without any UI showing and that means that something changed in the policy required by Android to run endless background services.
What puzzles me is whether an app like Slack even uses a foreground service when receiving chat messages
Most likely, they do not.
So if it's not using a foreground service but can receive messages while the UI is not shown and post a notification, how is this being done?
Most likely, on Google Play ecosystem devices, they are using Firebase Cloud Messaging (FCM) as a trigger to find out about messages that require user notification. FCM and its predecessors (C2DM and GCM) have been around for over a decade and are designed for this sort of problem.
if you look at the firebase messaging documentation you will be understood notifications that arrived to a client are not handled by the application, there is an Android transport layer (ATL) that is responsible for getting messages even if application is not running!

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.

Xamarin.Android - Keep the app working in background after closing it with a local notification

Currently, I have a mobile application written in Xamarin.Android. Because there are constant HTTP requests going on in the app, what I'd like to do is keep the application active after closing it.
What I am looking at, is for example after you close the app, in the background it keeps sending HTTP requests, but there is a local notification where when you click it you can open the app. There should be an explicit button for the exit which could be inside the application. In more details, HTTP requests are sent on some interval in seconds.
So my end goal is to have the app constantly running, if it's in a background, then show a notification that it's still up and be able to close it (even from the background) only from the inside of the app.
I couldn't find many resources specifically about this question and I am not quite sure what I can use in order to make this work.
Thanks in advance!
According to the documentation what you're trying to do is supported:
Sending notifications to the user
When a service is running, it can notify the user of events using
Toast Notifications or Status Bar Notifications.
A toast notification is a message that appears on the surface of the
current window for only a moment before disappearing. A status bar
notification provides an icon in the status bar with a message, which
the user can select in order to take an action (such as start an
activity).
Usually, a status bar notification is the best technique to use when
background work such as a file download has completed, and the user
can now act on it. When the user selects the notification from the
expanded view, the notification can start an activity (such as to
display the downloaded file).
See the Toast Notifications or Status Bar Notifications developer
guides for more information.
ref: https://developer.android.com/guide/components/services
ref: https://developer.android.com/guide/components/processes-and-threads

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.

Not show notification in status bar if app is running

I am implementing an android app that uses a service which posts notifications. I only want to display the notifications after the user has closed the app. Is it possible to not show notification in status bar if app is running?
You can work it around:
You could notify your service when the app has started (from the app), so it can remove the Notification instance.
The same, when your application has been closed by the user, before explicitly finishing the current activity, the app will notify the service to show the notification again.

Categories

Resources