Android Question OnGoingEvent not working

DarkSmart

Member
Licensed User
i use this code for show a notification:
B4X:
Dim ntf As NotificationBuilder
Dim bv As Notification
ntf.Initialize
        ntf.SmallIcon = "icon"
        ntf.Ticker = "test"
        ntf.DefaultLight = True
        ntf.DefaultVibrate = True
        Dim Sound As Boolean = True
        ntf.DefaultSound = Sound
        ntf.ContentTitle = "app"
        ntf.ContentText = "test"
        ntf.SubText = "Text"
        ntf.setActivity(chat)
        ntf.AutoCancel=True
        ntf.OnGoingEvent=False
        Dim p As Phone
        If p.SdkVersion >= 26 Then
            Dim ctxt As JavaObject
            ctxt.InitializeContext
            Dim manager As JavaObject
            manager.InitializeStatic("android.app.NotificationManager")
            Dim Channel As JavaObject
            Dim importance As String
            If Sound Then importance = "IMPORTANCE_DEFAULT" Else importance = "IMPORTANCE_LOW"
            Dim ChannelVisibleName As String = Application.LabelName
            Channel.InitializeNewInstance("android.app.NotificationChannel", _
                   Array("MyChannelId1", ChannelVisibleName, manager.GetField(importance)))
            manager = ctxt.RunMethod("getSystemService", Array("notification"))
            manager.RunMethod("createNotificationChannel", Array(Channel))
            Dim jo As JavaObject = ntf
            jo.RunMethod("setChannelId", Array("MyChannelId1"))
        End If
        bv.Initialize
        bv=ntf.GetNotification
        bv.Notify(2)
But OnGoingEvent = false is not working
such OnGoingEvent=true not worked
i use b4a version 9.01 and sdk 28
this not work in any device
i want my notification erasable and user can close this
help
what do i do?
 

Erel

B4X founder
Staff member
Licensed User
Longtime User
I recommend you to use NB6 class instead of this code.

Tip:
B4X:
bv.Initialize
bv=ntf.GetNotification
No reason to call Initialize here as you are setting a different object to the same variable.

Notifications are not persistent by default. If you are seeing a persistent notification then it is probably the automatic foreground notification: https://www.b4x.com/android/forum/threads/90546/#content
 
Upvote 0

DonManfred

Expert
Licensed User
Longtime User
Upvote 0
Top