B4A Library Notification Builder Library.

barx

Well-Known Member
Licensed User
Longtime User
Replied to pm
 

NeoTechni

Well-Known Member
Licensed User
Longtime User
Thank you.

What size image should we use for the big notification picture style? All I can find is the height needs to be a maximum of 256 dip, but nothing about the width. I tried using min(screenwidth, screenheight) but my image keeps getting cropped no matter what height I use
 

barx

Well-Known Member
Licensed User
Longtime User
The only thing I have read is 450dip wide with 2:1 ratio. But at that I would allow for some bleed either side. Not tested these sizes myself though, sorry.
 

NeoTechni

Well-Known Member
Licensed User
Longtime User
I blame Google for not making it automatically scale to fit... IT'S SIMPLE MATH!!!
 

NeoTechni

Well-Known Member
Licensed User
Longtime User
I got the math:

Width=Max(512dip, min(GetDeviceLayoutValues.Width, GetDeviceLayoutValues.Height)
Height=width*0.5

Start drawing X at 20dip instead of 0, and subtract 40dip from the Width so the edges aren't cut off
If you don't want the action buttons overlapping the image, then height = height * 0.75 (I'm sure there's an exact dip to use...)
 

Kevin

Well-Known Member
Licensed User
Longtime User
Thanks again for making this awesome lib! I've been away from my app for a while but am slowly getting back into it. The new group option sounded interesting so I tried to implement it in my app but when I do so, it doesn't work as expected. Perhaps I am doing something wrong?

If I set my primary notification to be the "GroupSummary" then only the main notification appears. If I do not set a "GroupSummary" then neither of them appear. It should also be mentioned that both notifications are extended and have 3 buttons on each of them.

This is on a Galaxy S5 running Android 4.4.2.

Prior to this new library update I was using an.Priority = -2 in order to prevent the secondary notification from adding a second icon to the top tray. I have tried the grouping with and without setting priority on the secondary notification.

Incomplete code...
B4X:
' Main notification...
Dim an As NotificationBuilder
    If an.IsInitialized = False Then an.Initialize()
    an.SmallIcon = "icon"
    an.AutoCancel = False: an.DefaultLight = False: an.DefaultSound = False: an.DefaultVibrate = False: an.OnGoingEvent = True: an.OnlyAlertOnce = True
    an.Group = "myapp"
    an.SortKey = "a" ' First in group
    an.GroupSummary = True

'...................

an.Notify (1)

B4X:
' Secondary notification...
Dim an As NotificationBuilder
    If an.IsInitialized = False Then an.Initialize()
    an.SmallIcon = "icon"
    an.AutoCancel = False: an.DefaultLight = False: an.DefaultSound = False: an.DefaultVibrate = False: an.OnGoingEvent = True: an.OnlyAlertOnce = True
    an.Group = "myapp"
    an.SortKey = "b" ' Second in group
    an.GroupSummary = False

'...................

an.Notify (2)

Any thoughts?
 

barx

Well-Known Member
Licensed User
Longtime User
Hi Kevin,

The Google documentations (and mine) state that the Grouped notifications may display as a cluster or stack on devices that support such feature. I guess this doesn't make it a predictable feature just yet until manufacturers start supporting it.

What I found in my tests, and I don't know if this is useful to you or not, is, the summary alone displays on the handheld (phone, etc) while the other group items will display on a connected Wear device.

At first, before testing I thought the same as you, that they would show up on the handheld as a stack much like an improved InboxStyle, but that does not seem to be the case.

Hope this helps
 

Kevin

Well-Known Member
Licensed User
Longtime User
Yeah, I just wasn't fully understanding that the grouping was specifically for wearables. I actually clicked the link in your original post listed under GroupSummary As Boolean (the same one you just provided) last night but I got a 404 error. I had assumed it was a dead link and didn't pay much attention to it but after trying it again today I saw that the link is just malformed... it has the </link> tag at the end as part of the URL. Reading the info at the link definitely clears it up!

Sorry about the misunderstanding.
 

barx

Well-Known Member
Licensed User
Longtime User
I will check that link out thanks, it was just auto generated from the library docs. Thanks for pointing it out to me.

And don't be sorry, These are brand new features, even I don't always know what to expect from them, lol
 

aaronk

Well-Known Member
Licensed User
Longtime User
Hi,

I am getting a error when I run the following code (I have attached the project as well) and can't work out why it's not working..

B4X:
Sub Globals
    'These global variables will be redeclared each time the activity is created.
    'These variables can only be accessed from this module.
    Dim nb As NotificationBuilder
End Sub

Sub Activity_Create(FirstTime AsBoolean)

    'Do not forget to load the layout file created with the visual designer. For example:

    'Activity.LoadLayout("Layout1")

    nb.Initialize
    nb.SmallIcon = "icon"
    nb.Ticker = "Ticker"
    nb.ContentTitle = "Title"
    nb.ContentText = "Text"
    nb.ContentInfo = "Info"
    nb.SubText = "SubText"
    nb.OnGoingEvent = True
    nb.AddAction("icon","Wait","Tag",Me)
    nb.Notify(1)
End Sub

When I run it on my device it comes up saying 'Unfortunately, NBTest has stopped'
And the IDE log shows:

B4X:
java.lang.NoClassDefFoundError: android.support.v4.app.NotificationCompat$Builder
at barxdroid.NotificationBuilder.NotificationBuilder.Initialize(NotificationBuilder.java:55)
at b4a.example.main._activity_create(main.java:318)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:515)
at anywheresoftware.b4a.BA.raiseEvent2(BA.java:175)
at b4a.example.main.afterFirstLayout(main.java:98)
at b4a.example.main.access$100(main.java:16)
at b4a.example.main$WaitForLayout.run(main.java:76)
at android.os.Handler.handleCallback(Handler.java:733)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:212)
at android.app.ActivityThread.main(ActivityThread.java:5151)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:515)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:878)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:694)
at dalvik.system.NativeStart.main(Native Method)

I am running:
Version 3.00 of the NotificationBuilder
I have copied android-support-v4.jar to my B4A Libraries folder
I am using B4A version 3.82

I can't work out why this is not working.

Any ideas ?
 

Attachments

  • NotificationBuilderDemo.zip
    6.2 KB · Views: 220

barx

Well-Known Member
Licensed User
Longtime User
Is it the latest version of the support lib? and make sure you don't have another support lib version in your standard b4a lib folder (this caught me out once)

p.s. the latest being revision 20
 

aaronk

Well-Known Member
Licensed User
Longtime User
Is it the latest version of the support lib?
p.s. the latest being revision 20

I copied the following file to my B4A Library folder:
AppData\Local\Android\android-sdk\extras\android\support\v4\android-support-v4.jar

(Hope this is the correct file?)
But it still shows the same error.

My B4A Library folder only has version 3.00 of this library in it.
 
Last edited:

aaronk

Well-Known Member
Licensed User
Longtime User
Worked it out..
I had to copy the file AppData\Local\Android\android-sdk\extras\android\support\v13\android-support-v13.jar to my B4A lib folder and it now works.

Is there a way to make the icon in the notification tray flash?
For Example make it display the icon then hide the icon then show it again etc ?
 
Last edited:

barx

Well-Known Member
Licensed User
Longtime User
It must still be an issue with you support-v4 revision, to check the revision of v4 you have, open sdk manager and it will tell you. It has worked withv13 as that also include v4, so you must have a newer v13.

As for the icon, the only way I can think of doing it it to use nb.setSmallIcon2. This allows you to use a LevelListDrawable (a drawable that can have multiple states, like showing %). I have never played with this, nor LevelListDrawables so couldn't advise you further.

There is an example on how to create the xml here
Doesn't seem to hard to be honest, you just need 2 levels: 1, icon shown, 2, transparent

Good luck and please report back how you get on to help others

Thanks
 

barx

Well-Known Member
Licensed User
Longtime User
Just thinking about it I guess you could just keep setting smallIcon, changing between to images

Remember either way you will need to recall notify again with same ID to update notification. And best to set AlertOnce to true so sounds, etc only happen once
 

imgsimonebiliato

Well-Known Member
Licensed User
Longtime User
Hello,
is it possible to set notification when the app isn't started and a certain hour?
For example, set a notification every day at 02:00 pm
 

Kevin

Well-Known Member
Licensed User
Longtime User
I use a service to accomplish this. You need to know the difference in TicksPerSecond between "now" and the desired time. In my example, my app gets the ending time of a TV show (CurrentShowEndTime as Long which is an Epoch timestamp) and does the math to figure out when to show the notification.

' Snipped from various code in my app to make a basic example...
B4X:
Dim tDelay, TimeToRestart as Long

tDelay = (CurrentShowEndTime - DateTime.Now)

TimeToRestart = DateTime.Now + tDelay * DateTime.TicksPerSecond

Dim TimeRemaining As Long
TimeRemaining = (TimeToRestart - DateTime.Now) / DateTime.TicksPerSecond
Log ("Seconds remaining until next notification = " & TimeRemaining)


CancelScheduledService ("") ' Make sure any previously scheduled services do not start
StartServiceAt ("", TimeToRestart, True) ' after selected delay passes

That code was called from the service itself. If you are calling it from a different part of the app, be sure to include the service name in the last two lines (between the quotes).

Hope this helps get you pointed in the right direction.

Edit to add that when the service starts, that is where you would show your notification. Then just stop the service and the notification should remain.
 
Cookies are required to use this site. You must accept them to continue using the site. Learn more…