Android Question [SOLVED] NB6 notification LED control

Gandalf

Member
Licensed User
Longtime User
Hello,

I'm testing notifications on two Chinese devices both running Android 8.1.0. Using NB6 example I have replaced NB6 class with latest version of corresponding library. The code:
B4X:
Sub Test_Notification
    Dim n As NB6
    n.Initialize("default", Application.LabelName, "DEFAULT").AutoCancel(True).SmallIcon(smiley)
    n.SetDefaults(True, False, True)
    n.SetLights(Colors.Green, 0, 0)
    n.Build("Title", "Content", "tag1", Me).Notify(124)
End Sub
It lights RED color on one device and no light at all on another one. These devices are capable of showing at least red and green lights - I can see them during charging. What I'm doing wrong? Is there any "best practice" for notification LED control?
 
Solution
I solved it at least for these particular devices. Looking at this thread I slightly modified NB6 library - changed this sub:
NB6.bas:
Public Sub SetLights (Clr As Int, OnMs As Int, OffMs As Int) As NB6
    If IsChannel Then
        Log("Using channel to set light")
        Channel.RunMethod("setLightColor", Array(Clr))
    Else
        Log("Using builder to set light")
        NotificationBuilder.RunMethod("setLights", Array(Clr, OnMs, OffMs))
    End If
    Return Me
End Sub

After that I have created separate subs in a service for each light color I need, pointing them to different notification channels:
someservice.bas:
Sub Regular_Notification (Title As String, Content As String) As Notification
    Dim n As NB6
    n.Initialize("default"...

Gandalf

Member
Licensed User
Longtime User
I solved it at least for these particular devices. Looking at this thread I slightly modified NB6 library - changed this sub:
NB6.bas:
Public Sub SetLights (Clr As Int, OnMs As Int, OffMs As Int) As NB6
    If IsChannel Then
        Log("Using channel to set light")
        Channel.RunMethod("setLightColor", Array(Clr))
    Else
        Log("Using builder to set light")
        NotificationBuilder.RunMethod("setLights", Array(Clr, OnMs, OffMs))
    End If
    Return Me
End Sub

After that I have created separate subs in a service for each light color I need, pointing them to different notification channels:
someservice.bas:
Sub Regular_Notification (Title As String, Content As String) As Notification
    Dim n As NB6
    n.Initialize("default", Application.LabelName, "LOW").AutoCancel(True).SmallIcon(NtfIcon)
    n.SetDefaults(False, False, False)
    Return n.Build(Title, Content, "tag1", Main)
End Sub

Sub RedLight_Notification (Title As String, Content As String) As Notification
    Dim n As NB6
    n.Initialize("redlight", Application.LabelName & "_Red_LED", "LOW").AutoCancel(True).SmallIcon(NtfIcon)
    n.SetLights(Colors.Red, 1, 0)
    Return n.Build(Title, Content, "tag2", Main)
End Sub

Sub GreenLight_Notification (Title As String, Content As String) As Notification
    Dim n As NB6
    n.Initialize("greenlight", Application.LabelName & "_Green_LED", "LOW").AutoCancel(True).SmallIcon(NtfIcon)
    n.SetLights(Colors.Green, 1, 0)
    Return n.Build(Title, Content, "tag3", Main)
End Sub

Now I just use them with the same notification ID number so they cancel previous one.
 
Upvote 0
Solution
Top