B4A Library Notification Builder Library.

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

  1. jairbj

    jairbj Member Licensed User

    Is there any way to display like a media player?

    I want to make a media player app and it should be recognized by Android as media player notification.


    I also would like to know how to make my "notification" always on top of the notification drawer (like spotify or deezer) regardless of notifications that come later.
    Last edited: Nov 14, 2017
  2. barx

    barx Well-Known Member Licensed User

    I think you are probably looking at a Custom Layout.
  3. hongbii khaw

    hongbii khaw Member Licensed User

    Hello Barx,
    First of all thanks for the library =D
    May I know how to set the notification to always repeat until the user click on it?
    Like the one in the normal notification:
    n.Insistent = true
    Thank you.
  4. Tasyo28

    Tasyo28 Member Licensed User

    Hi Barx Im new here in B4a and i saw your liblary so interesting but when i tried to run a sample code this error comes in the log.
    Please advise maybe i did something wrong.

    Sub Globals
    Dim nb As NotificationBuilder
    End Sub

    Sub Activity_Create(FirstTime As Boolean)
    'Do not forget to load the layout file created with the visual designer. For example:
        nb.SmallIcon = 
        nb.ContentTitle = 
    "Heads UP!"
        nb.ContentText = 
    "B4A is about."
        nb.Priority = 
    "arrow""Reply""Reply", Me) 'gfx are just some I had to hand, not much time to find others
        nb.AddAction("circle""Dismiss""Dismiss", Me)
    End Sub

    Sub Activity_Pause (UserClosed As Boolean)
    End Sub
    this is the error log
  5. Erel

    Erel Administrator Staff Member Licensed User

  6. DonManfred

    DonManfred Expert Licensed User

    As this command should not be inside the manifest-editor: i suggest to change the text to

    Add the following line to your Main activity Code.
    #additionaljar: com.android.support:support-v4
    Erel likes this.
  7. barx

    barx Well-Known Member Licensed User

    I would appreciate peoples thoughts on this update.
    This is just a test/beta release, hence it is not on the first post.
    Alos, this is my current take on things, I may have some bits wrong, things may change.

    I have finally got around to making some updates, mainly spurred on by googles recent mess that basically breaks existing Notification methods. The big change is the requirement for Notification Channels. I'm not going to go into what a channel is, you can read that here.

    Due to the way these channels work, this IS a breaking update. i.e. to use this library update, you will have to edit your existing code. The signature for the Initialize method has changed to specify the channel to post the notification to.

    A new object has been added called NotificationChannelBuilder. You create channels with this. The Channels are actually seperate to the notification. You create a Channel and then post a notification to the channel. Here is a simple example of the new setup:

    Dim NB As NotificationBuilder
    Dim Channel As NotificationChannelBuilder 'New object
    Dim ChannelID as String = "Channel_1"
    Dim ChannelName As String = "b4a News"
    'Build a Channel
    If Channel.ChannelsSupported Then
        Channel.Initialize(ChannelID, ChannelName, Channel.IMPORTANCE_DEFAULT)
    End If

    '<--Note the new parameter

    'rest of existing NotificationBuilder code
    As you can see in the code, we have to check if the device supports Channels. Google, in their infinite wisdom haven't made this backwards compatible so trying to create a Channel on a device older than API 26 Oreo will cause an error. The method ChannelsSupported simply returns whether the device API is >= 26. Having the ChannelID parameter in the .Initialize method does not cause any issue on older APIs.

    The new lib beta version is attached below for people to try. You will have to copy all 3 files (XML, JAR, AAR) to your additional libs folder and I also advise you clean any existing projects once code is updated (not sure if needed but I had a few errors whilst developing that went away with a clean).

    You shouldn't need any #additionalJar references anymore, they have been added to the lib. But you will need to make sure you have the latest support libs installed from google.

    Please let me know your thoughts on the implementation. I won't make this official until I get some feedback. I haven't got a Oreo device so this has only been tested on AVD's.

    p.s the version number is set to 3.50, it's been that long since I touched this code, I cannot remember where I'm at lol.

    p.p.s I will be hopefully added other missing updates to NotificationBuilder once I know this is working.

    Cheers for your time.

    Attached Files:

    iz0ndg, walterf25, An Schi and 4 others like this.
  8. Peter Simpson

    Peter Simpson Expert Licensed User

    A quick test, notifications appear to be working perfect here in services @barx :)

    Android Oreo 8.1.0...
  9. Peter Simpson

    Peter Simpson Expert Licensed User

    Hello @barx,
    I usually have the following lines of code set to 'False' for testing as I don't want to hear beeps or vibration noises every 60 seconds. Today I changed these lines from 'False' to 'True' and there appears to still be no vibration, sound or notification lights. I've tried different SDK Targets (23 to 27) and also different Channel.IMPORTANCE_xxx. The notifications themselves are fully working 100% though on the for mentioned SDK Targets

    'Like this
        Notification.DefaultVibrate = True
    Notification.DefaultSound = True
    Notification.DefaultLight = True
    Thank you.
  10. martin24

    martin24 Member Licensed User

  11. Peter Simpson

    Peter Simpson Expert Licensed User

    Thanks but I previously saw your post on Erels code feed and I tried the second channel and also changed the priority before making this post, it appeared to do the same for me...

    Check this out https://developer.android.com/guide/topics/ui/notifiers/notifications.html#ManageChannels
    Last edited: Dec 30, 2017
  12. barx

    barx Well-Known Member Licensed User

    Interesting, thanks for the feedback. So no sound, vib, lights at all?

    in your code, could you try
    also try explicitly setting those to true. Control of these items seems to be shared now but the docs do not state which gets priority. On my AVD I deffo get sound. No way to test lights or vibration.

    EDIT: On AVD Oreo I Don't get sound either, It was on Nougat I was getting sound. Let me look in more detail, see if I can get sound.

    Last edited: Dec 30, 2017
  13. barx

    barx Well-Known Member Licensed User

    If you long press on the notification, You will see some options. Then tap more settings. Then tap the channel name. You will see how the settings are for the channel. You can change these manually, but obviously we need to get these right in code. I'll come back shortly
  14. barx

    barx Well-Known Member Licensed User

    Another note, the settings cannot be changed by code on a channel once it is created, you have to either delete it or uninstall the app. then it will be re-created ;)
  15. Peter Simpson

    Peter Simpson Expert Licensed User

    Thank you @barx for your response. I had already tried the following before creating my previous post, I forgot to mention it, sorry.

    I had already tried the.
    Channel.EnableLights = True
    Channel.EnableVibration =
    I even added the following line to the manifest just to be sure.
    If I add the logs as you stated above they both return 'true' to both channel lights and channel vibrate. I've tried variants with IMPORTANCE_DEFAULT, IMPORTANCE_HIGH and IMPORTANCE_MAX, still nothing. But as I mentioned previously, the notifications all work perfectly.

    Thank you
    Last edited: Dec 30, 2017
  16. Peter Simpson

    Peter Simpson Expert Licensed User

    Hmm really, I'll give it a quick try. I did notice that If I used low importance I had to uninstall it as the notification would then stop, even when I changed it back to high again lol

    Give me 5 minutes...
  17. barx

    barx Well-Known Member Licensed User

    OOOOOOOOOOHH I got sound, It seems that sound only plays if the notification posts whilst the screen is off. Still digging
  18. Peter Simpson

    Peter Simpson Expert Licensed User

    Okay, it's still the same @barx,
    Everything is on, and in the settings you see the following, yes the default sound notification is working I tried it, I don't get sound even when the screen is off, also there's still no vibration.


  19. barx

    barx Well-Known Member Licensed User

    Something interesting happened here, AVD crashed, I had to cold boot it. Then sounds work with high importance, even whe screen is on.
  20. Peter Simpson

    Peter Simpson Expert Licensed User

    STOOOOOOOOOOP - @barx you're going to kill me.

    BOTH sound and vibrate are working, still no light though.

    I was a bit baffled why the sound was working for you but not me, so after thinking long and hard about it I suddenly remembered that I have a watch upstairs that might be on and connected to my phone. I took the watch off earlier today after I came back from the shops, so I went upstairs and turned my watch off. I then ran the test app and there was the default sound and vibration on my phone, no light though :rolleyes:

    Oops sorry, I completely forgot that watches also receive notification and my phone must be set to not make a noise or vibrate if my phone is connected to my watch as my watch will vibrate and show the notification for me :mad:
    Last edited: Dec 30, 2017
    barx likes this.
  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