Android Question [Solved] NB6 Notification with Foreground service

ac9ts

Active Member
Licensed User
Longtime User
I'm trying to use a simple NB6 class notification. I am placing the notification in a service that is started by "GUI" activity. n.Build returns a notification.

B4X:
Dim BM As Bitmap = LoadBitmapResize(File.DirAssets, "icon.png", 24dip, 24dip, False)
Dim n As NB6 
n.Initialize("default", Application.LabelName, "LOW").AutoCancel(False).SmallIcon(BM)
n.Build("Title", "Content", "tag1", GUI).Notify(4)
   
' Getting "Cannot assign void value." error on the following line
Service.AutomaticForegroundNotification = n.Build("Title", "Content", "tag1", GUI).Notify(4)
   
Service.AutomaticForegroundMode = Service.AUTOMATIC_FOREGROUND_ALWAYS
 

DonManfred

Expert
Licensed User
Longtime User
Try it like this
B4X:
dim noti As Notification = nb.build(...)
Service.AutomaticForegroundNotification = noti
noti.Notify(4)
 
Upvote 0

DonManfred

Expert
Licensed User
Longtime User
Explanation:
Service.AutomaticForegroundNotification needs a Notificationobject
B4X:
Service.AutomaticForegroundNotification = n.Build("Title", "Content", "tag1", GUI)
will work too but you dont have a Notificationobject which you need to Notify in this case...
So. Getting the Notification object, setting it to the Service, calling Notify on the Notification object.
 
Upvote 0

ac9ts

Active Member
Licensed User
Longtime User
B4X:
Service.AutomaticForegroundNotification = n.Build("Title", "Content", "tag1", GUI)
.

That's basically what I ended up using (for now). Once I fixed the error I originally received and got the code to compile, I was getting 2 notifications; 1 from the AutomaticForegroundNotification and the other from Notify(4).

I'm going to play around a bit with the class code as I would like to be able to change what is displayed on the AutomaticForegroundNotification notification while the service is running.
 
Upvote 0

DonManfred

Expert
Licensed User
Longtime User
Upvote 0

ac9ts

Active Member
Licensed User
Longtime User
Using .Notify(4) is what was causing the second notification above. I want to change what is on the notification held by
Service.AutomaticForegroundNotification which stays as long as the service is running.
 
Upvote 0
Top