B4A Library Notification Builder Library.

Discussion in 'Additional libraries, classes and official updates' started by barx, Mar 17, 2013.

  1. Peter Simpson

    Peter Simpson Expert Licensed User

    I've just sent you a PM...
     
  2. barx

    barx Well-Known Member Licensed 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)
     
  3. barx

    barx Well-Known Member Licensed 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 likes this.
  4. Peter Simpson

    Peter Simpson Expert Licensed 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 :D
     
    Last edited: Jan 1, 2018
    barx likes this.
  5. barx

    barx Well-Known Member Licensed User

    And to you kind sir :D
     
  6. stefanoa

    stefanoa Active Member Licensed User

    Why does not show the icons?

    Main:
    Code:
    #additionaljar: com.android.support:support-v4
    Globals:
    Code:
    Dim nb As NotificationBuilder
    Code:
    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)
    [​IMG]
    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: Feb 26, 2018
  7. barx

    barx Well-Known Member Licensed 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!"
     
    Peter Simpson and DonManfred like this.
  8. stefanoa

    stefanoa Active Member Licensed 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. ?
    [​IMG]
     
    Last edited: Feb 26, 2018
  9. barx

    barx Well-Known Member Licensed 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.
     
    Peter Simpson and stefanoa like this.
  10. stefanoa

    stefanoa Active Member Licensed User

    How can i set CustomLayout STYLE? The SETSTYLE method does not provide the CustomLayout as a parameter, but only BigText, BinPicture and Inbox
    Code:
    ...
    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?
     
  11. DonManfred

    DonManfred Expert Licensed User

    Search the 27 pages of this thread. Somewhere Barx posted an example with two CustomLayouts... I found it yesterday
     
    Peter Simpson likes this.
  12. barx

    barx Well-Known Member Licensed User

    Code:
    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....
     
    Peter Simpson likes this.
  13. stefanoa

    stefanoa Active Member Licensed User

    Ok, after countless attempts, I made this layout.

    [​IMG]

    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:
    Code:
    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: Mar 4, 2018
    Peter Simpson likes this.
  14. barx

    barx Well-Known Member Licensed 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 ;)
     
  15. konradwalsh

    konradwalsh Active Member Licensed User

    Could you please share how?
    I have read all 27 pages of this thread and still none the wiser.
     
  16. stefanoa

    stefanoa Active Member Licensed User

    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!

    Code:
    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"64dip64dipTrue)
        
    Else
            bmp = LoadBitmapResize(
    File.DirAssets, "pausenotification.png"64dip64dipTrue)
        
    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
     
    Aldaghir and konradwalsh like this.
  17. PassionDEV

    PassionDEV Active Member Licensed User

    is it necessary to add #additionaljar: com.android.support:support-v4 in version 8 ?

    because i see the notifcation works without adding this addtional jar
     
  18. barx

    barx Well-Known Member Licensed 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
     
  19. Abdou1283

    Abdou1283 Member Licensed User

    please can you post an example explicating how to build music player notification
     
  20. Robert Valentino

    Robert Valentino Well-Known Member Licensed User

    Abdou1283 could you post your "songnotification" file so I can see what it looks like
     
Loading...
  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice