Android Question Heads-up notifications when app is not open

Semen Matusovskiy

Well-Known Member
Licensed User
Hi, guys --

I send notifications from FireBaseMessaging service (StartAtBoot: True).

I tried to find a sample on forums, but nothing works with closed application. I set priority_high in NotificationBuilder (IMPORTANCE_HIGH in notification). Turned on sound, ongoingevent etc. But maximum result is heads-up, when activity is opened. May be it's possible to stimulate Android somehow ? I need a solution for API14+, including Android 8.
 

Semen Matusovskiy

Well-Known Member
Licensed User
This is a mistake. Watch the video tutorial.

I watched. But nothing changed. I agree that StartAtBoot has no effect.

I tried a lot of combinations. For example,

B4X:
Sub firebasemessagingInstance_MessageArrived (Message As RemoteMessage)

    Dim notificationbuilderInstance                                             As NotificationBuilder
 
    If Common.bytePhoneSdkVersion >= 26 Then
        firebasemessagingInstance_MessageArrived_API26 (Message)
    Else
        notificationbuilderInstance.Initialize
        notificationbuilderInstance.ContentTitle = Message.GetData.Get ("title")
        notificationbuilderInstance.ContentText  = Message.GetData.Get ("body")
        notificationbuilderInstance.SmallIcon    = "icon"
        notificationbuilderInstance.Priority = 2
        notificationbuilderInstance.AutoCancel   = True
        notificationbuilderInstance.DefaultSound = True
        notificationbuilderInstance.OnGoingEvent = True
        notificationbuilderInstance.setActivity (Main)
        notificationbuilderInstance.Notify (1)
    End If

End Sub

Sub firebasemessagingInstance_MessageArrived_API26 (Message As RemoteMessage)

    Dim notificationInstance                                                    As Notification

    notificationInstance.Initialize2 (notificationInstance.IMPORTANCE_HIGH)
    notificationInstance.AutoCancel = True
    notificationInstance.Icon = "icon"
    notificationInstance.Sound = True
    notificationInstance.OnGoingEvent = True
    notificationInstance.SetInfo (Message.GetData.Get ("title"), Message.GetData.Get ("body"), Main)
    notificationInstance.Notify (1)

End Sub

Results are the same. When an app is opened, the notification appears like expected (popup and sound). But when the app is closed, no sound and doesn't popup. Unlike new notification appears in tray.

It looks that code as it is correct. Probably, the reason in permissions. My son uses Xiaomi redmi 4x for tests. He read an article https://www.androidcentral.com/how-fix-push-notifications-miui-8 and changed some flags, using GMail as layout. After this the phone began to show notifications correctly (even if my app is not started, there is a sound, and message popups). Unf., my son is not Android developer and can't explain details.
 
Last edited:
Upvote 0
Cookies are required to use this site. You must accept them to continue using the site. Learn more…