Android Question Invalid notification (No small icon)

Philip Prins

Active Member
Licensed User
Hello

I am using NB6 and get an error no small icon
Target SDK 26
B4A 9.50

B4X:
Public Sub CreateNotification(TitleX As String, ContentX As String)
    
    Debug(TitleX &" "& ContentX)

    Dim n As NB6
    n.Initialize("default", Application.LabelName, "DEFAULT").AutoCancel(True).SmallIcon(icon)
    Dim cs As CSBuilder
    n.SubText(cs.Initialize.BackgroundColor(Colors.Yellow).Append("Sub text").PopAll)
    Dim Title As Object = cs.Initialize.Color(Colors.Green).Append(TitleX).PopAll
    Dim Content As Object = cs.Initialize.Underline.Bold.Append(ContentX).PopAll
    Dim largeIcon As Bitmap = LoadBitmapResize(File.DirAssets, "logo.png", 256dip, 256dip, True)
    n.LargeIcon(largeIcon)
    n.Color(Colors.Blue)
    n.BadgeIconType("SMALL").Number(1)
    n.ShowWhen(DateTime.Now)
    n.Build(Title, Content, "tag2", Me).Notify(5)

End Sub
I do not know why
 

Philip Prins

Active Member
Licensed User
You did not specify a small icon. n.SmallIcon(...)
I copied the code from an Erel example , there is no small n.small icon.
Hen i add
B4X:
n.SmallIcon(icon)
I get an error :Caused by: java.lang.NullPointerException: Attempt to invoke virtual method 'int android.graphics.drawable.Icon.getType()' on a null object reference
 

DonManfred

Expert
Licensed User
there is no small n.small icon.
from nb6 class

B4X:
'Sets the status bar icon. The icon size should be 24 x 24.
Public Sub SmallIcon (Icon As Bitmap) As NB6
    If IsBuilder Then
        NotificationBuilder.RunMethod("setSmallIcon", Array(CreateIconFromBitmap(Icon)))
    End If
    Return Me
End Sub
 

Philip Prins

Active Member
Licensed User
from nb6 class

B4X:
'Sets the status bar icon. The icon size should be 24 x 24.
Public Sub SmallIcon (Icon As Bitmap) As NB6
    If IsBuilder Then
        NotificationBuilder.RunMethod("setSmallIcon", Array(CreateIconFromBitmap(Icon)))
    End If
    Return Me
End Sub

Solved , loaded the icon after create notification

Now

B4X:
Public Sub CreateNotification(TitleX As String, ContentX As String)
    icon = LoadBitmapResize(File.DirAssets, "logox.png", 24dip, 24dip, False)
    Debug(TitleX &" "& ContentX)

    Dim n As NB6
    n.Initialize("default", Application.LabelName, "DEFAULT").AutoCancel(True).SmallIcon(icon)
    Dim cs As CSBuilder
    n.SubText(cs.Initialize.BackgroundColor(Colors.Yellow).Append(" ").PopAll)
    Dim Title As Object = cs.Initialize.Color(Colors.Green).Append(TitleX).PopAll
    Dim Content As Object = cs.Initialize.Underline.Bold.Append(ContentX).PopAll
    Dim largeIcon As Bitmap = LoadBitmapResize(File.DirAssets, "logo.png", 256dip, 256dip, True)

    n.LargeIcon(largeIcon)
    n.Color(Colors.Blue)
    n.BadgeIconType("SMALL").Number(1)
    n.ShowWhen(DateTime.Now)
    n.Build(Title, Content, "tag2", Me).Notify(5)

End Sub
 
Top