Android Question NB6 Long Message

MarcoRome

Expert
Licensed User
Longtime User
Hi all i have this code:

B4X:
Sub fm_MessageArrived (Message As RemoteMessage)
    Log("Message arrived")
    Log($"Message data: ${Message.GetData}"$)

    Dim n As NB6
    n.Initialize("default", Application.LabelName, "DEFAULT").AutoCancel(True).SmallIcon(smiley)
    Dim cs As CSBuilder
    n.SubText(cs.Initialize.BackgroundColor(Colors.Yellow).Append("Messaggio").PopAll)
    Dim title As Object = cs.Initialize.Color(Colors.Red).Append(Message.GetData.Get("title")).PopAll
    Dim Content As Object = cs.Initialize.Underline.Bold.Append($"${Message.GetData.Get("body")}"$).PopAll
    Dim largeIcon As Bitmap = LoadBitmapResize(File.DirAssets, "pizza_ico.png", 250dip, 250dip, True)
    n.LargeIcon(largeIcon)
    n.Color(Colors.Blue)
    n.BadgeIconType("SMALL").Number(1)
    n.ShowWhen(DateTime.Now)
    n.Build(title, Content, "tag2", Main).Notify(5)
   
    
End Sub

Now the question is if i have in body an message very long ( more lines ) example:
"vediamo un messaggio molto più lungo cosa succede..dsafsdjkflsdafjk jklasdflj asdflkòdsf ajklsòdfldkjl fsad f aksjfaksjldfkjdfasdkljf sadklfkasdfkjldsf jasdkf asdklfjkasdf jkas dfjkafkasdl fjasdf"

I have this result:

upload_2018-7-10_15-30-12.png


all in one line.... any idea ?
Thank you
 

DonManfred

Expert
Licensed User
Longtime User
I guess the feature comes from Android.
As it shows all in one line the contentlength is limited (max visible chars),

Though you can put the hole text into the TAG of the notification to reveal all when you click on the Notification.

Get some inspiration here.
 
Upvote 0

MarcoRome

Expert
Licensed User
Longtime User
Hi Don. Thank you resolved with this code:

B4X:
    Dim n As NB6
    n.Initialize("default", Application.LabelName, "DEFAULT").AutoCancel(True).SmallIcon(smiley)
    Dim cs As CSBuilder
    n.BigTextStyle(Message.GetData.Get("title"), cs.Initialize.BackgroundColor(Colors.Yellow).Append("Messaggio").PopAll, _
    $"${Message.GetData.Get("body")}"$ _
     )
    Dim largeIcon As Bitmap = LoadBitmapResize(File.DirAssets, "pizza_ico.png", 250dip, 250dip, True)
    n.LargeIcon(largeIcon)
    n.Color(Colors.Blue)
    n.BadgeIconType("SMALL").Number(1)
    n.ShowWhen(DateTime.Now)
    n.Build(Message.GetData.Get("title"), "Contenuto...", "tag", Me).Notify(8)
 
Upvote 0

MarcoRome

Expert
Licensed User
Longtime User
Hi Don. Thank you resolved with this code:

B4X:
    Dim n As NB6
    n.Initialize("default", Application.LabelName, "DEFAULT").AutoCancel(True).SmallIcon(smiley)
    Dim cs As CSBuilder
    n.BigTextStyle(Message.GetData.Get("title"), cs.Initialize.BackgroundColor(Colors.Yellow).Append("Messaggio").PopAll, _
    $"${Message.GetData.Get("body")}"$ _
     )
    Dim largeIcon As Bitmap = LoadBitmapResize(File.DirAssets, "pizza_ico.png", 250dip, 250dip, True)
    n.LargeIcon(largeIcon)
    n.Color(Colors.Blue)
    n.BadgeIconType("SMALL").Number(1)
    n.ShowWhen(DateTime.Now)
    n.Build(Message.GetData.Get("title"), "Contenuto...", "tag", Me).Notify(8)

UPDATE
- This code work without problem on Android 8 / 7.
But if i use:
1. Android 5.1.1 ( Samsung Galaxy J3 ) i have anyway 1 line.
2. Android 5.1 ( Huawey P80 ) i havent notification


I resolved with mix NotificationBuilder and Nb6:

B4X:
    'Qui controllo se al di sootto di Android 8.0
    Dim sdkversion As Int
    Dim jo As JavaObject
    sdkversion = jo.InitializeStatic("android.os.Build$VERSION").GetField("SDK_INT")
    If sdkversion < 26 Then
        Dim cn As NotificationBuilder
        Dim cn1 As NotificationBigTextStyle
        If cn1.IsInitialized = False Then cn1.Initialize
        If  cn.IsInitialized = False Then  cn.Initialize
        cn1.BigText = Message.GetData.Get("title")  & CRLF & Message.GetData.Get("body")
        cn1.SummaryText = "Apri Pizza Eat"
        cn.SmallIcon = "icon"
        cn.DefaultLight = True
        cn.DefaultVibrate = False
        cn.DefaultSound = True
        cn.ContentInfo = ""
        cn.AutoCancel = True
        cn.ContentTitle = "Notifica Pizza Eat"
        cn.ContentText = "Notifica Pizza Eat"
        cn.setActivity(Main)
        cn.SetStyle(cn1)
        cn.Notify(1)
    Else
        Dim n As NB6
        n.Initialize("default", Application.LabelName, "DEFAULT").AutoCancel(True).SmallIcon(smiley)
        Dim cs As CSBuilder
        n.BigTextStyle(Message.GetData.Get("title"), cs.Initialize.BackgroundColor(Colors.Yellow).Append("Messaggio").PopAll, _
    $"${Message.GetData.Get("body")}"$ _
     )
        Dim largeIcon As Bitmap = LoadBitmapResize(File.DirAssets, "pizza_ico.png", 250dip, 250dip, True)
        n.LargeIcon(largeIcon)
        n.Color(Colors.Blue)
        n.BadgeIconType("SMALL").Number(1)
        n.ShowWhen(DateTime.Now)
        n.Build(Message.GetData.Get("title"), "Contenuto...", "tag", Me).Notify(8)
            
    End If
 
Upvote 0

MarcoRome

Expert
Licensed User
Longtime User
UPDATE
- This code work without problem on Android 8 / 7.
But if i use:
1. Android 5.1.1 ( Samsung Galaxy J3 ) i have anyway 1 line.
2. Android 5.1 ( Huawey P80 ) i havent notification


I resolved with mix NotificationBuilder and Nb6:

B4X:
    'Qui controllo se al di sootto di Android 8.0
    Dim sdkversion As Int
    Dim jo As JavaObject
    sdkversion = jo.InitializeStatic("android.os.Build$VERSION").GetField("SDK_INT")
    If sdkversion < 26 Then
        Dim cn As NotificationBuilder
        Dim cn1 As NotificationBigTextStyle
        If cn1.IsInitialized = False Then cn1.Initialize
        If  cn.IsInitialized = False Then  cn.Initialize
        cn1.BigText = Message.GetData.Get("title")  & CRLF & Message.GetData.Get("body")
        cn1.SummaryText = "Apri Pizza Eat"
        cn.SmallIcon = "icon"
        cn.DefaultLight = True
        cn.DefaultVibrate = False
        cn.DefaultSound = True
        cn.ContentInfo = ""
        cn.AutoCancel = True
        cn.ContentTitle = "Notifica Pizza Eat"
        cn.ContentText = "Notifica Pizza Eat"
        cn.setActivity(Main)
        cn.SetStyle(cn1)
        cn.Notify(1)
    Else
        Dim n As NB6
        n.Initialize("default", Application.LabelName, "DEFAULT").AutoCancel(True).SmallIcon(smiley)
        Dim cs As CSBuilder
        n.BigTextStyle(Message.GetData.Get("title"), cs.Initialize.BackgroundColor(Colors.Yellow).Append("Messaggio").PopAll, _
    $"${Message.GetData.Get("body")}"$ _
     )
        Dim largeIcon As Bitmap = LoadBitmapResize(File.DirAssets, "pizza_ico.png", 250dip, 250dip, True)
        n.LargeIcon(largeIcon)
        n.Color(Colors.Blue)
        n.BadgeIconType("SMALL").Number(1)
        n.ShowWhen(DateTime.Now)
        n.Build(Message.GetData.Get("title"), "Contenuto...", "tag", Me).Notify(8)
           
    End If


As confirmed By Erel ( https://www.b4x.com/android/forum/threads/nb6-largeicon-for-oldnotification.93095/#post-589221 )
 
Upvote 0

Similar Threads

Top