Not show notification in status bar if app is running - android

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.

Related

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

notification click event, best way to show activity data from service while app is closed android

i have made an app where i made a unbound service that is continuously requesting to server api, if server send json then notification will show and on notification click i take the user to one activity to show some data. everything working well while apps is opened or background. but when the app is closed, notification showing but when on notification click trigger to specific activity, there is no data showing(data should come through a server req).
what is the best way to do this?

How to hide app in notification bar [duplicate]

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).

Firebase Push Notification Android when application is closed

I'm developing an application dealing with push notifications. I have used firebase for this purpose. The requirement is as such on clicking notification , the 3rd activity of the application must open up . I was successful in achieving the same when application is in background and foreground . But when application is killed and on tap of the received notification , it takes me to launcher screen . what should i do to redirect a notification click to the activity i want when the application is killed ?

Android - Handle local notification when app in foreground

My app receives FCM and fires local notifications, which open target activities. This works fine if the local notification is clicked when the app is not running.
But, if the local notification is clicked when my app is already running (foreground or background), I don't want to open the target activity but shows an AlertDialog first. So, the activities stack is not changed and the user can continue what he was doing before.
It seems the local notification must have an action, which opens activities. Is there anyway achieve what I wanted above?
I think you have to stop sending push notification when you app is in foreground
check if your app is in foreground or by following this link
check android application is in foreground or not?
check this in firebaseMessegingService class before sending PN and manage alert dialog appearance according that

Categories

Resources