Android - Handle local notification when app in foreground - android

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

Related

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 ?

OneSignal Push Notification Failed when user kill the application

I have implemented push notification with OneSingal APIs in my android project. I'm facing an issue while clicking the push notification, that i was unable to launch the specified screen when the user click the push notification, If the user kill the app from background(long press and remove the pplication from list of apps). I have registered the Open/Receiver handlers in application class. Seems like, the handlers are no more visible in the app, when user kill/remove the app from background.
Please help me to resolve the issue.
Unfortunately Android apps are not able to receive notifications when they have been force-closed. This is part of the design of the Android OS.

GCM - Opening app from notification?

I'm working on an app which is using GCM for push notification.
My question is around how to open/start the app from when user clicks the notification.
I have two potential scenarios:
A) The app is open and is resident in either foreground or background, either way my GCM works fine, the GCM message arrives user taps notification and intent starts relevant activity (passed via the notification pending intent).
B) The app is closed and notification received, the user again taps the notification and the intent tries to start the relevant activity and this is where it gets messy.
The app has a back-end and so needs to auto-login/authenticate now if I try to start the same activity the credentials etc are out of date or dont exist therefore the app crashes. I need to launch the app from scratch in this case rather than simply start the particular activity via the pending-intent.
My question therefore is how do I tell the GCM listener to check if app running and if so simply start activity and if not (app is closed) launch app as normal?
thanks.
Ok solved this, not sure if its the best way but appears to work without issue.
What I ended up doing was creating a static boolean variable in launcher activity.
This is set true when app starts and the GCM listener tests for this variables state on incoming GCM notif (will always be true for life of app instance), if true go directly to activity else (app closed or stale) launch app.
This seems to work fine from what I can see, still interested in a better method as this does seem hackish?

Bring the Android app to foreground after recieving a notification push like the application launcher

In my case, I receive a notification message and open an Activity say 'X'. After closing it I want to bring my application again to foreground like the behavior of the Application launcher.
In more details I want to see if my app in the background, bring it to foreground. If not, restart it.
Any suggestions, please?
You can use getRunningAppProcesses() in ActivityManager. And then check your package name in the list of running Processes.
if you need to start or open your activity when user click on Notification then just use Intent to call your main activity or home page that's it. have you Google your problem?
See the documents of Notification Notification
and for Intent
it may helpful for you
Use C2DM - cloud to device message to listen for the notification and launch your app.

Persist Android Notifications Event If App is Terminated?

In my app, when a user executes and event, I add a notification to the notification's bar. Tapping that notification works both if the app is in the foreground or if it is backgrounded.
I would like the notification to persist even if the app is terminated (due to memory, etc.). And have the notification tap relaunch the app.
Is that, at all, possible?
I've searched all over and can't find an answer.
I have set my notification flags to Notification.FLAG_NO_CLEAR so the user can't clear it, but upon app termination, the notification gets removed.
You probably want the notification to be managed by a service. Services can be configured to restart automatically on termination.

Categories

Resources