I'm developing an android app integrating GCM notification capabilities. everything works fine, means I receive the notification (sound + icon on the notification bar) but I would like to display automatically the notification preview on the screen to the end user (when the device is unlocked) for 1 or 2 seconds.
How can I do that ? is there a specific parameter in the notification to permit this preview ?
As soon as the notification is received, I would like to show it to the end user for 2 or 3 seconds and then remains in the notification bar:
Then, end user can see the notification and the content automatically (a bit intrusive but I just want to know if this is possible)
What you are looking for is called a Heads-up Notification and can only be done in 5.0+
Related
How to implement notification like a voice call in LINE, Messenger, WhatsApp or any voice call app? when anyone calls to you, it will show screen accept or reject even though the app runs on background mode. Currently, I implement notification using FCM https://capacitor.ionicframework.com/docs/guides/push-notifications-firebase/ it works but I want notification like incoming call then user accepts it will open some link with capacitor InAppBrowser. (the notification should have a sound for ringing about a minute and show screen) because of normal notification, it won't work when the user leaves the phone.
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.
I am developing a react-native app with a video call feature and need it to display a 'heads up' notification that lasts for 40 seconds when the user receives a call, but the notification only displays for about three seconds before disappearing. I have tried setting the category to 'call' and priority to 'max' on Android 6.0 but to no avail.
An image displaying a notification for an incoming call:
You should use the equivalent to the setFullScreenIntent() API on your notification:
An intent to launch instead of posting the notification to the status bar. Only for use with extremely high-priority notifications demanding the user's immediate attention, such as an incoming phone call or alarm clock that the user has explicitly set to a particular time.
The system UI may choose to display a heads-up notification, instead of launching this intent, while the user is using the device.
When you set a full screen Intent on your Notification, two things happen:
When the screen is off, the activity you've set via the full screen intent is launched instead of the notification being posted.
When the screen is on, your notification will be posted as a heads up notification that will be persistent (it won't collapse to the status bar unlike a normal heads up notification).
I have an application in which it receives the notification when fired from Backend. Now what I want to achieve is that the notification should disappear after 2 minutes if user has not clicked on it (even if my app is killed or background). I know that this can be achieved by using the Notification manager's setTimeoutAfter() but that will work only if am making my custom notification using Notifcation Manger.But i want to dismiss the Notification generated by System after 2 minutes.
Any kind of suggestion or help will be welcomed.
It is not possible to do that. The default system notification builder is pretty bare bones and will not handle it. The best you can do is set a delivery timeout so if the device was off it won't get the notification once it expires.
See https://firebase.google.com/docs/cloud-messaging/concept-options#when_to_use_platform_specific_keys (only works on Android and Web)
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'