B4A Library Notification Builder Library.

barx

Well-Known Member
Licensed User
Longtime User
@Peter Simpson LOL
Lights have only worked when screen is off for a long while.

So to test you have to post notification when screen is off.

In the demo app I .Notify on activity_pause (If not user_closed). Seems to work enough to get led working. (not tested on oreo mind)
 

barx

Well-Known Member
Licensed User
Longtime User
I have tested that the lights still operate as expected on my real device, and they do but like I say it's only API 24. Not much more I can do really at the moment as it is the newest device I have and don't plan on upgrading anytime soon.
 

Peter Simpson

Expert
Licensed User
Longtime User
Good morning @barx and a happy new year to you

Well notifications, vibrate and sound worked great from the off and is still working (dam watch ). I've not seen the light but maybe that's just me missing it. Anyway it's working on 8.1.0 and anyway I personally don't think that I even setup lights in my previous.

Thanks again for your hard work and dedication to the cause.

Top of the morning to you
 
Last edited:

barx

Well-Known Member
Licensed User
Longtime User

And to you kind sir
 

stefanoa

Active Member
Licensed User
Longtime User
Why does not show the icons?

Main:
B4X:
#additionaljar: com.android.support:support-v4

Globals:
B4X:
    Dim nb As NotificationBuilder
B4X:
nb.Initialize
    nb.SmallIcon = "icon"
    nb.ContentTitle = "Heads UP!"
    nb.ContentText = "B4A is about."
    nb.Priority = 1
    nb.setActivity(Me)
    nb.AddAction("pausered","Pause","TagPause",callFormPause)
    nb.AddAction("playred", "Play","TagPlay",callFormPlay)
    nb.AddAction("exit", "Exit", "TagExit", callFormExit)
    nb.Notify(1)


The 3 icons png (pausered.png, playred.png and exit.png) are in folder .\Objects\res\drawable and are read-only.
Can you help me? Thanks
 
Last edited:

barx

Well-Known Member
Licensed User
Longtime User


Copied from elsewhere...

"This is not an error, but a change in the design with Android Nougat. They still are required for older devices and Android Wear devices!"
 

stefanoa

Active Member
Licensed User
Longtime User
Copied from elsewhere...

"This is not an error, but a change in the design with Android Nougat. They still are required for older devices and Android Wear devices!"
Thanks, but can you suggest me how create a notification for music player like Spotify or similar that have icons Play/Pause/Backward/Forward in addition to the Song Title, Album, etc. ?
 
Last edited:

barx

Well-Known Member
Licensed User
Longtime User
Thanks, but can you suggest me how create a notification for music player like Spotify or similar that have icons Play/Pause/Backward/Forward in addition to the Song Title, Album, etc. ?

That looks to me to be using a media style notification. If that is not the case, then it is likely to be a custom layout.
 

stefanoa

Active Member
Licensed User
Longtime User
That looks to me to be using a media style notification. If that is not the case, then it is likely to be a custom layout.
How can i set CustomLayout STYLE? The SETSTYLE method does not provide the CustomLayout as a parameter, but only BigText, BinPicture and Inbox
B4X:
...
Dim notificationBuilder As NotificationBuilder
Dim nbCustomStyle As NotificationCustomLayout
...
notificationBuilder.Initialize
...
nbCustomStyle.Initialize("songnotification")
nbCustomStyle.SetImage("cover",coverImage) 
nbCustomStyle.SetTextColor("songTitle",Colors.Black)
nbCustomStyle.SetTextColor("albumTitle",Colors.Blue)
  
notificationBuilder.SetStyle(nbCustomStyle) <<<<<<< ERROR !!!!!

notificationBuilder.Notify(1)
...

Is there a complete example with the CustomLayout?
 

barx

Well-Known Member
Licensed User
Longtime User
B4X:
notificationBuilder.CustomLayout(nbCustomStyle)

Please note, there are many guidelines from google for custom layouts but i personally have found them nothing but trouble. One of the main issues is that some android versions or devicesshow the wrong default colour, which can make your text vanish lol. Best way is to explicitly set all colours rather than rely on system defaults.

I think spotify set the background colour to explicitly be black....
 

stefanoa

Active Member
Licensed User
Longtime User
Ok, after countless attempts, I made this layout.



Some questions:
1) Is there a way to perform a function in the activity, without returning to the activity itself and remaining on the notification? (if I press "next song" I would like to play it without going back to the activity)
2) can i increase the height of notification? I tried in various ways but it always remains the same height
3) [SOLVED] how set notification in the TOP of the notifications list ([SOLVED] nb.Priority=1 or 2)

In Activity_Resume:
B4X:
    Dim mIntent As Intent = Activity.GetStartingIntent
    If mIntent.HasExtra("Notification_Click_Tag") Then
        Dim action As String = mIntent.GetExtra("Notification_Click_Tag")     
        If action = "Exit" Then       
            nb.Cancel(1)                   
            setPauseMode
        else If action = "Play" Then
            playButton_Click
        else If action = "Next" Then
            nextSongButton_Click
        else If action = "Previous" Then
            previousSongButton_Click
        End If
    End If

thanks
 
Last edited:

barx

Well-Known Member
Licensed User
Longtime User

Firstly, good to see have made some prgress. I personally didn't have the time or patience. I will try to answer your questions below,

1) swap from a activity to a service for the actions
2) The height of a normal layout is set, I believe you will need to look at BigCustomLayout
 

konradwalsh

Active Member
Licensed User
Longtime User
Could you please share how?
I have read all 27 pages of this thread and still none the wiser.
 

stefanoa

Active Member
Licensed User
Longtime User
Could you please share how?
I have read all 27 pages of this thread and still none the wiser.
This is a part of the code extracted from my function.
I struggled a lot to understand it, but I hope it will be useful!

B4X:
Sub Notification
    '--- Starter is a service ! ---
    If Starter.currentFileLocation = "" Then Return
    
    nb.Initialize
    nb.SmallIcon = "icon"
    nb.Ticker = "Ticker"
    
    '--- parameters ---
    nb.OnGoingEvent=True
    nb.Number = 1
    nb.DefaultLight = False
    nb.DefaultSound = False
    nb.DefaultVibrate = False
      
    nbCustomStyle.Initialize("songnotification")

    '--- coverimage is a bitmap! ---
    If coverImage.IsInitialized Then
        nbCustomStyle.SetImage("Cover",coverImage)
    End If
    nbCustomStyle.SetTextColor("Title",Colors.White)
    nbCustomStyle.SetTextColor("Album",Colors.Gray)
    
    '--- Starter is a service ! ---
    Dim pSongNameNew As String=Starter.currentSong
    Dim pAlbumNameNew As String=Starter.currentAlbum
    Dim pArtistNameNew As String=Starter.currentArtist
    
    '--- reduce strings lenght ... ---
    If Starter.currentSong.Length>23 Then
        pSongNameNew=Starter.currentSong.SubString2(0,23) & "..."
    End If
    If Starter.currentAlbum.Length>26 Then
        pAlbumNameNew=Starter.currentAlbum.SubString2(0,26) & "..."
    End If
    If Starter.currentArtist.Length>26 Then
        pArtistNameNew=Starter.currentArtist.SubString2(0,26) & "..."
    End If
    
    nbCustomStyle.SetTextField("Title", pSongNameNew)
    nbCustomStyle.SetTextField("Album", pAlbumNameNew)
    nbCustomStyle.SetTextField("Artist", pArtistNameNew)
    
    If Starter.MediaIsPaused=True Then
        bmp = LoadBitmapResize(File.DirAssets, "playnotification.png", 64dip, 64dip, True)
    Else
        bmp = LoadBitmapResize(File.DirAssets, "pausenotification.png", 64dip, 64dip, True)
    End If
    nbCustomStyle.SetImage("PlayPause",bmp)
    
    '--- Call the button events --- 
    nbCustomStyle.setEnableClickEvent("Previous", Player, "PreviousSong")
    nbCustomStyle.setEnableClickEvent("PlayPause", Player, "PlayPauseSong")
    nbCustomStyle.setEnableClickEvent("Next", Player, "NextSong")
    nbCustomStyle.setEnableClickEvent("status_bar_collapse", Player, "ExitApp")
        
    nb.CustomLayout=nbCustomStyle
    nb.Priority=1    
    nb.Notify(1)
End Sub
 

barx

Well-Known Member
Licensed User
Longtime User
Hi everyone,

In light of all the current issues relating to notifications in Android. I have decided to upload the source code for NotificationBuilder library to gitHub. I hope this will help some with there issues, and help them see 1) how the library works and 2) how the methods and properties relate to the java code you have no doubt come across when trying to deal with your own issues. I am doing this as I really don't have time to get it all up to date. I started over xmas when I have some days off work, but never completed the update as there was so much.

Please note: there may be some open ends. i.e new methods that aren't complete or fully tested.

Feel free to use the code however you wish. Carry on extending the library or take parts and make a new library.

https://github.com/oobarxoo/NotificationBuilder
 

Abdou1283

Member
Licensed User
Longtime User
please can you post an example explicating how to build music player notification
 
Cookies are required to use this site. You must accept them to continue using the site. Learn more…