Notifier questions

jscoulter

Member
Licensed User
Longtime User
Hi All.

I have a question about the notifier.
Is it possible to have a notifier have Ongoing messages, i.e. one that can not be removed, and messages that can be removed?
I tried creating 2 notification objects, but this didnt work :)

Thanks, Jeremy
 

jscoulter

Member
Licensed User
Longtime User
Ok, I did that and yip it worked how I wanted. great.
However, what I am not sure about is where I make the call.
I just assumed I would put "Service.StartForeground" and "Service.StopForeground" in the Service_Start and Service_Destroy procedures. Is that the right place to do it?

Jeremy
 
Upvote 0

Erel

B4X founder
Staff member
Licensed User
Longtime User
I just assumed I would put "Service.StartForeground" and "Service.StopForeground" in the Service_Start and Service_Destroy procedures. Is that the right place to do it?
Sounds good. There is no single right place. It depends on your application needs.
Make sure to provide a way to the user to stop your service. Once it is marked as a foreground service it will not be destroyed by the OS.
 
Upvote 0

jscoulter

Member
Licensed User
Longtime User
Yes I have added a menu with an option to close the app which calls "ExitApplication". I expect that will do the trick?

Jeremy
 
Upvote 0

jscoulter

Member
Licensed User
Longtime User
I want to come back to this now that I have tidied up some other bits.

What happens is, when the app starts it creates the ongoing notification, no problems there.
Also, I have a notification added when an SMS is received.
And this is where my problem starts.
When a new notification is created, it creates another icon with the notification number displayed.
So if I receive say 3 SMS messages I would have one App icon for the ongoing part, then 3 seperate icons with 1,2,3 on the icons.

When the service starts I do the following:

If oNotification.IsInitialized = False Then oNotification.Initialize

oNotification.Icon = "icon"
oNotification.AutoCancel = True
oNotification.SetInfo("My App","My App started", Main)
Service.StartForeground(1,oNotification)

This creates the ongoing event notification. All good there.
So now an SMS comes in and I then call this Sub

Sub AddNotification(sTitle As String,sMessage As String)
iNotificationID=iNotificationID+1

oNotification.SetInfo(sTitle, sMessage, Main)
oNotification.number=iNotificationId
oNotification.Notify(iNotificationID)
DoEvents
End Sub

I cant work out why it keeps adding the icons. Can you help?

Jeremy
 
Upvote 0

jscoulter

Member
Licensed User
Longtime User
I found part of the issue.

oNotification.Notify(iNotificationID)

iNotificationID is an internal counter of how many notifications there are so that it knows how many to clean up when the app. closes.
I didnt realise that the ID was the ID of the notification item :)

However, there is still an issue.
I cant get the main notification icon to update wiht the number of notifications when I set oNotification.number=iNotificationId
I have to go oNotification.Notify(2) which creates another icon that DOES update, i.e. no matter how many notifications I create, the second icon updates with the number of notificaitons.
So If you are able, can someone indicate how I update the main notification icon? or is it not possible?

Thank,Jeremy
 
Upvote 0

jscoulter

Member
Licensed User
Longtime User
ok, one more bit of info.

if I DONT pass an incremental number to oNotification.Notify() and pit in an ID of say 2, oNotification.Notify(2), yes it updates the second notification icon with the number of notifications, BUT when you drag the notification bar down, there is only ONE notification in there, not how ever many you have received.

I MUST be missing something !

Jeremy
 
Upvote 0

jscoulter

Member
Licensed User
Longtime User
I think you have missed the point here.

I only want ONE notification icon. I dont want 2 icons.
I thought I was being clear about that :(

So, maybe to make it clearer, here is what I want to happen:

App. starts, Icon is created. The service starts foreground and I get an ongoing notification. (already happening)
SMS comes in notification the "same" icon above gets updated to show that the notification count has changed. an no other icons appear.

Is this possible, or do I have to have 2 icons. That really what I am trying to find out. I have other apps that I have downloaded that have one icon that show notifications such as email programs etc.

Jeremy
 
Upvote 0

Erel

B4X founder
Staff member
Licensed User
Longtime User
Something like this?
B4X:
Sub Globals
    Dim n1 As Notification
End Sub

Sub Activity_Create(FirstTime As Boolean)
    n1.Initialize
    n1.Icon = "icon"
    n1.SetInfo("n1", "n1", "")
    n1.Notify(1)
End Sub
Sub Activity_Click
    n1.SetInfo("n1", n1.Number & " messages", "")
    n1.Number = n1.Number + 1
    n1.Cancel(1)
    n1.Notify(1)
End Sub
Each time you press on the activity the number will go up by one.
 
Upvote 0

jscoulter

Member
Licensed User
Longtime User
Sort of....but not really.

The issue really is there is no point in displaying the number on the notification when there is no way to manipulate the displayed number based on user interaction.

The ideal, and I know this is not what it does now, but the ideal is it WOULD somehow do this is:

Something happens to trigger a notification.
New icon is created with "1" displayed on it to show there is one notification.

Something happens to trigger a notification.
New icon is created with "2" displayed on it to show there are two notifications.

The user drags down the notification bar. They see 2 notification messages. They click on one of the notification messages........at this point the application goes...ah the user click on a notification. I now only have ONE notification, and it updated the notification icon to show a "1" now not a 2.

I relealise this requires non-existant functionality, but I see no point in showing the number of notifications because it would/could be wrong.
Guess I wll just forget this part of my app and think of something else.

Jeremy
 
Upvote 0

Erel

B4X founder
Staff member
Licensed User
Longtime User
Now I better understand your requirements. As you noticed there could be only one message per icon.
There is one event which you can handle related to notifications.
When the user presses on a notification the target activity will be resumed. You can create an activity that shows the list of all messages.
In Activity_Resume sub clear the current notification(s).
 
Upvote 0
Top