How to increase duration of heads up for Android notification - android

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).

Related

Start foreground service without popping up a notification in android

An android foreground service needs a notification, which is fine, but I would rather have it go directly to the notification background without first obscuring the UI for 3 seconds.
Is there a combination of settings for the notification builder and or the notification channel, which will give me the small icon in the notification bar as well as the notification, when expanding the notification list, but without showing a notification on top of the ui for about three seconds?
My issue is not that I want to hide anything, but rather that the application is in use by the user after the foreground service is being started, so the popup is annoying.

Cancel notification without using Notification Manager

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)

Android GCM message - how to get preview of the notification

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+

How to receive Parse push notification only when app is opened, and show it in modal dialog form

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'

I want open a dialog box containing message periodically to users of app

We want to send messages to app users either through notifications, dialog box or image opening up on their screen every 24 hours telling them that our app is running on their phone.
We were looking to use Notification builder but it has limitation that it only works for api 11 and above and half of all app installations today are for earlier api versions. We are trying to find out which would be the best way to go with this.
I'm not sure what "Notification builder" is, but you can certainly use Notification and NotificationManager in any API you want.
So, putting it all together, I would use AlarmManager to fire off an alarm every 24 hours. Set up this alarm when your application runs, and in a BroadcastReceiver which is configured to receive BOOT_COMPLETED. The BOOT_COMPLETED notification allows you to quietly restart the alarm if the device reboots.
The alarm triggers another BroadcastReceiver which puts the notification up. If the user selects the notification, then your application is launched. Mostly, the presence of the notification will be all the reminder your user will need.
My notes say that NotificationManager can pop a View up onto the screen, which could be a dialog. However, I think a simple icon in the status bar would be best, since you're just reminding the user that the application is present.
Oh, p.s., if your application is a service that's running in the background 24/7, then you should also remember to restart it in the BOOT_COMPLETED broadcast.

Categories

Resources