B4A Library Notification Builder Library.

barx

Well-Known Member
Licensed User
Longtime User
The documentation states an example of

file:///sdcard/notification/ringer.mp3

NOTE the 3 /'s

I doubt the sound will be played from assets folder, I think you will have to copy to somewhere else first.
 

fishwolf

Well-Known Member
Licensed User
Longtime User
The documentation states an example of



NOTE the 3 /'s

I doubt the sound will be played from assets folder, I think you will have to copy to somewhere else first.

SoundPool object work fine with sound file into "Files" folder

Sin was a good library....
 

barx

Well-Known Member
Licensed User
Longtime User
OK I just tried this out and I can confirm it works.

I downloaded a random notification .mp3. Copied it to the sdcard under

SDCard/notification/notification.mp3

Then I used the code

B4X:
nb.CustomSound = "file:///mnt/extSdCard/notification/notification.mp3"

the path to the sdcard on samsung s4's being /mnt/extSdCard/

worked straight away.
 

barx

Well-Known Member
Licensed User
Longtime User
It doesn't seem to work from assets so like I said copy it first. i.e. copy to File.DirInternal then use

B4X:
nb.CustomSound = "file:///" & File.Combine(File.DirInternal, "File.mp3")

That should also work but not tested it.
 

fishwolf

Well-Known Member
Licensed User
Longtime User

sorry, but doesn't work fine
 

NeoTechni

Well-Known Member
Licensed User
Longtime User
Could we have the source for your test apk? I'm having some trouble setting it up.
 

barx

Well-Known Member
Licensed User
Longtime User
At the moment it is part way through the update. The source is rather complex due to code output etc. I have noticed and fixed one little issue with the existing demo app. It didn't show to initialize an object. So this will be fixed in the updated release. What issues are you having?
 

NeoTechni

Well-Known Member
Licensed User
Longtime User
It wasn't showing, but it did once I set a small icon.

Now I am having a problem where the actions I add have a background set to almost the same color as the text, making it hard to read.

 
Last edited:

NeoTechni

Well-Known Member
Licensed User
Longtime User
For editing an existing notification, is there a way to remove actions or should I just initialize and start over?
 

barx

Well-Known Member
Licensed User
Longtime User
It wasn't showing, but it did once I set a small icon.

Now I am having a problem where the actions I add have a background set to almost the same color as the text, making it hard to read.


Yes, you need to set a smallIcon

hmmm, somebody else had this issue before, cannot remember the outcome. What's your TargetSDK set to in the manifest. And what version of android are you running it on?

Thanks
 

barx

Well-Known Member
Licensed User
Longtime User
For editing an existing notification, is there a way to remove actions or should I just initialize and start over?

Start over and use the same ID.
 

NeoTechni

Well-Known Member
Licensed User
Longtime User
I haven't set a TargetSDK number. What minimum do you suggest?
Turns out I need a maximum of 10 to get the : menu button
I am running it on android 4.4
 
Last edited:

NeoTechni

Well-Known Member
Licensed User
Longtime User
Is there a way I can use the customlayout to add my own buttons, then use some variation of this code to add a click event handler?

B4X:
'Set a new click event for a view which includes the WidgetId so we can decide from which widget the event was fired.
'After setting an event with this sub the standard B4A event for this view will not work anymore.
'
' ServiceName - The name of the WidgetService
' WidgetId - Id of the widget
' rv - RemoteViews object
' ViewName - Name of the view for which the event is set
' EventName - The name of the event. A "_clicked" is appended to this event.
Public Sub SetWidgetClickEvent(ServiceName As String, WidgetId As Int, pRv As RemoteViews, ViewName As String, EventName As String)
    Dim vIntent As Object, vPendingIntent As Object, ref As Reflector, ViewId As Int

    vIntent = ref.RunStaticMethod("anywheresoftware.b4a.keywords.Common", "getComponentIntent", Array As Object(ref.GetProcessBA(ServiceName), Null), Array As String("anywheresoftware.b4a.BA", "java.lang.Object"))
    ref.Target = vIntent
    EventName = EventName.ToLowerCase
    ref.RunMethod4("putExtra", Array As Object("b4a_internal_event", EventName & "_clicked"), Array As String("java.lang.String", "java.lang.String"))
    ref.RunMethod4("putExtra", Array As Object("appWidgetId", WidgetId), Array As String("java.lang.String", "java.lang.int"))

    ref.Target = pRv
    ViewId = ref.RunMethod4("getIdForView", Array As Object(ref.GetProcessBA(ServiceName), ViewName), Array As String("anywheresoftware.b4a.BA", "java.lang.String"))

    vPendingIntent = ref.RunStaticMethod("android.app.PendingIntent", "getService", Array As Object(ref.GetContext, WidgetId, vIntent, 134217728), Array As String("android.content.Context", "java.lang.int", "android.content.Intent", "java.lang.int"))
    ref.RunMethod("checkNull")
    ref.Target = ref.GetField("current")
    ref.RunMethod4("setOnClickPendingIntent", Array As Object(ViewId, vPendingIntent), Array As String("java.lang.int", "android.app.PendingIntent"))

    UpdateSingleWidget(pRv, WidgetId)
End Sub

Public Sub UpdateSingleWidget(pRv As RemoteViews, WidgetId As Int)
   Dim Obj1 As Reflector, Obj2 As Reflector, current As Object
   Obj1.Target = pRv ' a RemoteViewsWrapper
   Obj1.RunMethod("checkNull") 'does some internal checking and may set current
   current = Obj1.GetField("current") ' a RemoteViews - get this after checkNull
   Obj2.Target = Obj1.RunStaticMethod("android.appwidget.AppWidgetManager", "getInstance", Array As Object(Obj1.GetContext), Array As String("android.content.Context"))
   Obj2.RunMethod4("updateAppWidget", Array As Object(WidgetId, current), Array As String("java.lang.int", "android.widget.RemoteViews"))
   Obj1.SetField2("current", Null)
End Sub

The problem is, it's not a widget...

Or would using a B4A layout allow for click event handlers?
 

barx

Well-Known Member
Licensed User
Longtime User
OK Folks,

I am very happy to announce that the Library has been updated to Version 3. I have added what I can to the original post but unfortunately I have had to cut a few non Vital bits of text out as I hit the 30000 char limit of a single forum post.

See the first post for the updated library files, please make sure you update you support v4 too using the android sdk manager.

This update is mostly related to adding support for Wear Specific devices. It really is a brilliant platform.

Hope this is useful to you all.

As usual, let me know if there are any issues. I have done a fair amount of testing but I am only human....

The demo app has also been updated to demonstrate much of the new features.
 

barx

Well-Known Member
Licensed User
Longtime User

Version 3 has a new method:

NotificationCustomLayout > setEnableClickEvent(). This adds the onClickPendingIntent.

Call this, passing the name of the view as defined in the xml layout and it should now register the touch. I tried it on a simple layout with text labels and it appears to work well.
 

manolitoGnet

Member
Licensed User
Longtime User
Wow, wow, wow. Really a nice and well documented job.

Tx!
 

NeoTechni

Well-Known Member
Licensed User
Longtime User
I noticed Android allows for icons larger than the size of the actual available space for it. So I cheated.

 

Eliezio

Member
Licensed User
Longtime User
Hey Guys!

Could anybody please help me? I've been, for three days now, trying to use this library to do pretty simple things. But it happens that all the time I try to execute that routine to do a notification I keep getting this error: "java.lang.NoClassDefFoundError: android.support.v4.app.NotificationManagerCompat".

Am I missing anything? What would be your advices?

I've read sth about the JDK version used on Eclise to compile the android-support-v4.jar that could be an influence for this error, but it seems like nobody above had this same issue?

Ohh... and my B4A version is 3.0

Any help would be highly appreciated!
Thanks
 
Cookies are required to use this site. You must accept them to continue using the site. Learn more…