I am building an social media app in Android studio, this app uses firebase for push notifications, and notifications is working fine, that Is notifications shows on device's notification bar.
How can I change the behavior so that the notification can appear as popup when app is in foreground?
I want a persistent kind of notification, something like WhatsApp that can stay on top other apps so that users can quickly open notification on wherever they are on their phone.
On my research, the best i could get was to use this on my theme
But I do not have Theme.Holo.Dialog in my style and my aim is that the notification should appear even if app is not open.
Thank you for looking into this
You should use heads-up notifications
For this purposes you should use notification channel with high a importance: How to set importance in the notification channel.
In this answer you can find code sample, how to show notification in the channel with high importance(to show notification even if the app in the foreground):
https://stackoverflow.com/a/67953864/16210149
Hope it would be helpful.
Related
I understand the Notification Badge on the launcher icon in Android (8.0+) is automatically shown when a notification is received. Unfortunately, once they open or dismiss the notification the badge will be removed. What I'm wondering is, can the app itself directly tell the system to show the badge? I would like to show it when they have unread messages within the app.
I understand that some third party launchers and manufacturer variants of Android do offer additional badge functionality, however, I am referring to vanilla Android and the stock launcher.
Thank you.
I understand the Notification Badge on the launcher icon in Android (8.0+) is automatically shown when a notification is received
Only if the launcher supports it. There are hundreds of launchers.
can the app itself directly tell the system to show the badge?
In terms of the standard Android SDK system, the badge will only appear if you raise a notification. Some launchers may offer an additional (documented or undocumented) API for apps to display badges on icons.
This video # 0:17 shows a bubble-style push notification on Android. Messaging apps like WhatsApp often use these.
I'm building an app with Capacitor 3 but can't find how to send these kinds of push notifications. Is there a plugin I could use, or some way of configuring just a normal push notification to display like this?
It turns out this is the default style when the 'brief' notification style is selected in the notifications setting on the phone. It isn't set programmatically as some kind of notification config.
Mine wasn't showing because the 'Show as popup' option was disabled for the notification channel I was testing. When I created a new channel, it was set to show notifications as popups, and then they started showing like in the video.
I am using nativescript-plugin-firebase for the APP and I get the notifications when the app is closed.
However, if the app is open I don't get any notifications. Is there any way to force showing push notifications even when the app is open or do I have to create a custom notification with sound within the app?
Another problem that I have is the way the push notifications are displayed. I use Laravel-FCM to send push notifications from the server-side, I have the priority set to 'high' and everything else set to default but when I receive the notification to the android device there is no floating notification, only a badge icon and a notification in the notifications center.
In the app notifications settings, there is Miscellaneous Notification Category with Importance set to Default, Vibration set to OFF and LED Light is also OFF but if I manually change those settings then firebase notifications appear with floating notification and vibration.
Any way to actually make these notifications with high priority by default?
P.S. The device I am testing on is Xiaomi Redmi Note 8 Pro
I have the same problem when using Nativescript-firebase as yours. When the app is open, the push notification is delivered but not shown (see onMessageReceived callback) then you can use Nativescript-local-notification to show the content of the push notification received when app is open.
This is the first time I am integrating notifications into my application. I am using Firebase. Setup was extremely simple and I am able to view the notification in the tray.
So, when the application is open, and if it receives a notification. I would like to display the notification in the activity itself.
How should I go about this?
You can look at Gmail approach. If there is new mail in current thread, they show SnackBar with notification.
You need to determinate connected parts of your app. And if notification connected to part where current user is - show SnackBar, and if there is something completely different - show heads-up notification.
Guide how to do Heads-Up notifications here
Guide how to do SnackBar notifications here
Have you ever tried Pushbots , its an infra- Structure for Notifications , it has more interesting Features than Firebase. Give it a shot.
Pushbots link
I was using https://github.com/ParsePlatform/PushTutorial sample code for a while.
Current example behavior is
Push notification will be received, either the app is opened or closed.
Push notification is in the form of showing icon in status bar with sound.
I cannot find a way to specific notification icon image. Parse is using app icon as notification icon by default. By Android design guideline requires us to have different style and size for notification icon.
When the app is opened, and notification received. Clicking on the notification icon will cause 2nd instance of the same app is launched. That's mean, there will be 2 instances of same app. (Personally, I don't feel this is a correct behavior)
I was wondering
How can I only receive the push notification when app is opened, but not closed?
How can I show it in the form of modal dialog, instance of showing icon in status bar with sound?
I am not sure about the 4th point, it didn't work that way for me. It opened the same instance for me. I think you are using a different application identifier and have two different application with same name and icon, but different identifier.
Now, for your use case, I think Push notification is not the ideal solution. Depending on what and how frequent you need to show this, you may opt for a repeating pull from the server or if you still want to use Push Notification then subscribe/unsubscribe from a Push Notification Channel when the app is pulled to foreground or background.
ie, when the application is in foreground (onStart() / onResume()), subscribe to a channel:
PushService.subscribe(context, "foregroundPush", YourActivity.class);
and when the application is moving to background (onStop() / onResume() / onDestroy() ), unsubscribe from the same channel:
PushService.unsubscribe(context, "foregroundPush", YourActivity.class);
Whenever you need to send a push notification to the devices with your application in foreground, use the channel 'foregroundPush'