Is it possible in android to show a persistent popup on notification? - android

I would like to know if it is possible to have a popup appear in the middle of the screen when recieving a notification and my app is on the background or closed. I would then want the popup to remain there untill clicked on. Is this possible on Android?
I am using flutter with firebase but I would just like to know if it is possible at all on android.

You cannot do it with a notification. But using https://pub.dev/packages/system_alert_window you can overlay custom UI over other apps. I ended up using the cloud messaging onBackgroundMessage to trigger this overlay.

Related

How to control whether to display notification or not based on the screen that is being displayed in android studio?

I am making a chat application and I am using Firebase Cloud Messaging to send push notifications. Everything is working fine but I do not want to display notification if the app is already in chat screen. I am using jetpack compose for UI and have single-activity architecture.
So in my chat screen, I don't want to display the notification. However, if the user is at other screens, I want to display the notification.
How can I achieve this?
There can be two possible solutions
Declare boolean in Activity or SharedPreference and toggle value according to lifecycle event's.
Once you receive firebase notification send broadcast and listen in activity. Inside activity identify top most visible screen using navController like below and decide wheather to show notification or not.
val visibleScreenRoute = parentNavController.currentBackStackEntry?.destination?.route?.split(Constants.KEY_QUESTION_MARK)?.getOrNull(0)
Hope this will help you to solve the issue.
I have the same case as you.
First, you need to create a custom notification and control push notifications manually.
Second, you have a module which checks whether activity is displaying or not.
Finally, when you receive notification data from firebase, using above module to decide display notification or not.
Check this document for more details : Build Notification

Is it possible to react to a notification being displayed while app is in foreground? Android Compose

Is there a way to listen to notifications and know if a specific notification is displayed while my app is in foreground?
I need to refresh screen data when a specific notification is received and is shown on screen.
I'm using Android and Compose and I found NotificationListenerService, but was wondering if there are newer ways to do it?

How do I remove a notification without removing its bubble while the app is not in foreground?

In my app I'm publishing notifications for chats, and whenever a chat is read by user, I want to remove the notificaton. If the user has opted to open a bubble, however, I want to preserve it until the user manuall dismisses it.
I can easily do this when the user opens the relevant chat in the bubble itself, or in the main activity, by republishing the notification with .setSuppressNotification(true) called on its bubble metadata. The effect is what I want exactly; the notification is gone, the bubble stays, and the badge is cleared on the bubble.
The problem is, the user can also read the chat elsewhere, not on the device. In this case .setSuppressNotification() might not work:
This flag has no effect if the app posting the bubble is not in the foreground. The app is considered foreground if it is visible and on the screen, note that a foreground service does not qualify.
Is there a way to remove a notification without removing its bubble while the app is in background?
P.S. What do the other apps do?
Telegram seems to be preserving the bubble, only removing relevant notifications when you open the bubble itself. The notifications will stay even if you read the chat in main activity and dismiss the bubble. I don't think this is acceptable;
Signal, on the other hand, will kill the bubble whenever you open the relevant chat in the app. This is perhaps reasonable for one-to-one chats, as the bubble will reappear on a new message anyway, but for group chats I would like to preserve the bubble;
People (the sample app) will preserve the bubble while removing the notification. Being not a real messenger, it doesn't have to deal with my specific use case, however.
You can try NotificationListenerService
Request user to enable permission Notification access
Cancel Notification using NotificationListenerService
do not use NotificationService#cancel
I found a Github sample here (not mine): https://github.com/Chagall/notification-listener-service-example
You can follow the sample here and implement some more code to make it happen
I created an issue about this on Google's tracker and they marked it as fixed, saying
We would like to inform you, setSuppressNotification will work regardless of the app being in the foreground and this change has been introduced in Android S.

Clear Notification on Android programmatically without remove Chat Bubbles

I got a problem with Android Notification while developing my Messaging App.
My App need to clear notification on Status Bar, so I call Notification#cancel(id)
But this function also close the Chat Bubble relate to this Notification.
I tried hundreds way to clear Notification on Status Bar & keep Bubbles on Screen but can't
Any one here face this problem and has the solution yet?
Instead of cancelling the notification, you can republish it while calling setSuppressNotification(true) on it's bubble metadata & setOnlyAlertOnce(true) on its builder. It will keep the bubble and remove the notification along with the bubble badge and launcher shortcut badges, if any.
Beware that for this to work, your app must be visible on the screen.

How to create lock screen notifications in my app?

I'm trying to create a custom notification in my android app with an image that will also be visible when the phone is locked.
Right now, Im building push notifications which are visible on the notification bar only, in which only my app icon is visible and on clicking which a certain pending intent is executed.
Is there a way through which i can show, my notifications with an image and a headline with it and also it gets visible on locked screen .
Also is there any widgets available or particular libraries through which i can implement my custom notifications?
Try using alertdialog with a flag. The flag_show_when_locked is the thing you trying to do I suppose. Please refer to this answer here.

Categories

Resources