Android Question How to create a Full-Screen Notification in B4A for Android 9?

madrigal115

Member
Licensed User
Hello,
I am trying to show a full-screen notification in B4A when a new order arrives. I want it to open an Activity called Request.




Here is my code snippet:
How do I correctly create a PendingIntent in B4A using JavaObject to open an Activity?:
Dim n As NB6
Dim cs As CSBuilder
Dim bmpSign As Bitmap = LoadBitmapResize(File.DirAssets, "sign.png", 24dip, 24dip, False)
Dim title As Object = cs.Initialize.Color(Colors.Red).Append("Caution:").PopAll
Dim Content As Object = cs.Initialize.Append("This app may drain your battery!").PopAll
Dim largeIcon As Bitmap = LoadBitmapResize(File.DirAssets, "Small Cartoon.png", 256dip, 256dip, True)
n.Initialize("default", Application.LabelName, "DEFAULT").AutoCancel(True).SmallIcon(bmpSign)
n.LargeIcon(largeIcon)
' Here I want to open Request Activity
' n.FullScreenIntent = ???
Return n.Build(title, Content, "tag", Me)
 

Erel

B4X founder
Staff member
Licensed User
Longtime User
1.
B4X:
Private Sub FullScreen_Notification
    Dim n As NB6
    n.Initialize("full_screen", Application.LabelName, "HIGH").SmallIcon(smiley)
    n.SetFullScreen(Main)
    n.Build("Title", "Content", "tag1", Main).Notify(4)
End Sub
2. Extract NB6.bas from the b4xlib and add to your project.
3. Add to that class:
B4X:
Public Sub SetFullScreen(Activity As Object) As NB6
    If IsBuilder = False Then Return Me
    Dim in As Intent = CreateIntent(Activity, False)
    in.Flags = Bit.Or(268435456, 131072) 'FLAG_ACTIVITY_NEW_TASK and FLAG_ACTIVITY_REORDER_TO_FRONT
    Dim PendingIntent As Object = PendingIntentStatic.RunMethod("getActivity", Array(ctxt, Rnd(0, 0x7fffffff), in, GetPendingIntentFlag))
    NotificationBuilder.RunMethod("setFullScreenIntent", Array(PendingIntent, True))
    Return Me
End Sub
4. Add to the manifest editor:
B4X:
AddPermission(Manifest.permission.USE_FULL_SCREEN_INTENT)

It is not exactly clear when it actually shows a full screen intent:

Try to lock the device before showing the notification.
 
Upvote 0
Top