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.
Related
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.
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.
i want to pop-up a dialog while some specific event occurs. Say i am an antivirus and found a virus, i can't send notification for this right, user could be compromised even dead until he checks the notification.
So i want to show a dialog like allow-deny, or yes-no, not to disturb user, it's gonna happen very rarely.
So is there any way that a service or application shows a dialog while user is using another application, even playing a game.
Thanks in advance...
Have a look at the Notification documentation. I don't believe you can/should create an AlertDialog when its not in the foreground. See here for Android's information on design patterns regarding when you should and shouldn't use them (you're interested in the last paragraph.
To quote the documentation.
Dialogs and toasts are for feedback not notification
Your app should not create a dialog or toast if it is not currently on screen. Dialogs and Toasts should only be displayed as the immediate response to the user taking an action inside of your app. For further guidance on the use of dialogs and toasts, refer to Confirming & Acknowledging.
This is a better, less intrusive way of notifying the user in your specific case. I also know that its possible to create a notification from a background service.
You create the Notification using the Notification.Builder class, setting things like title, icon, text, when to display it and also the intent to launch when the user clicks on the notification (used to open your app at a desired location). Once created you then use the startForeground(NOTIFICATION_ID,notification). You specify an id so you can access the notification later.
My intention is to display a notification with a personalised icon. However, if a notification with the same id is already displayed and then I need to add a new notification with the same id, my program will instead prepare a "stacked" version of the notification where the icon is changed to some generic icon and the notification content shows excerpts from the last and current notifications. Similar to how Gmail does when there are multiple emails.
To implement that I need to check if there are notifications of my app, currently displayed. I do not see any API to retrieve my own notifications.
I cannot simply cache the notification details that I have displayed till now, since in that case I need to know when they will be dismissed by the user, and update my cache accordingly. I also do not see any API to listen for dismiss events.
If you observe the gmail app notification behaviour properly u will notice that even when u dismiss one notification gmail shows you the same notification again in the list when a new notification comes. It looks to me that gmail is relying on total unread/unopened messages rather than keeping a cache of notifications.
There is no direct api for ur suggested SDK version. You need to fallback to ur own implementation. However, there is a way to know if a already showed notification was dismissed - How to know when my notification is cleared via Clear button?
This is possible with android 4.3 upwards now
See http://developer.android.com/reference/android/service/notification/NotificationListenerService.html#getActiveNotifications()
I m a newbie to android development and i wanna know a right way to get notification as an activity instead of statusbar notification.
To be clear, i wanna display an notification on screen instead of adding it to status bar.
In that case you shouldn't call it notification. In Android, a notification is something that ends up in the status bar and that the user can deal with at her own leisure.
An activity will take over the complete screen and force the user to deal with it immediately. That is very intrusive and users will likely get annoyed, unless the information you show is really crucial.
The correct behaviour is to post a notification and bring up your activity when the user clicks on the notification, very much like your messaging client or email client.
Other options are bringing up a dialogue or a toaster message. A dialogue is a message the user will have to interact with to go away, whereas a toaster message will be visible for a short time and then automatically disappear.
Maybe you could be a bit more specific about what sort of information you want to provide to the user?
Surely you can be helped out.
I feel that you are getting notifications from a web service as a response to some request, right?
If yes, then you can display them in a custom made dialog box, or inside an activity whose theme has been set as DIALOG.
maybe I got your question wrong, maybe your talking about the notifications about networks, calls and things.
If its so, correct me.
Thanks!
Android 2.3 introduced a new field on Notification, fullScreenIntent, for exactly this purpose. Place a PendingIntent here that will trigger whatever activity you'd like to display, and the user will be sent to that activity (whether full-screen or dialog-themed) in addition to receiving the usual notification icon in the status bar. As of Gingerbread, this is how the Phone app implements the incoming call screen.