B4A Library Notification Builder Library.

barx

Well-Known Member
Licensed User
Longtime User
I don't have a deal of spare time at the moment but if you could post a sample project with your custom layout and code it will allow me to check it out without having to build it all. Thanks
 

Mrjoey

Active Member
Licensed User
Longtime User
I don't have a deal of spare time at the moment but if you could post a sample project with your custom layout and code it will allow me to check it out without having to build it all. Thanks
B4X:
Nbuild.Initialize
Nbuild.SmallIcon = "icon"
Nbuild.setActivity(Main)
Nbuild.DefaultLight = False
Nbuild.DefaultVibrate = False
Nbuild.DefaultSound = False
Nbuild.ContentTitle = "Aux Music Player"
Nbuild.ContentText = ""
Nbuild.SubText = ""
Nbuild.OnGoingEvent = True
Nbuild.Priority = 1
cl.setEnableClickEvent("NPrev",Me,"Prev")
cl.setEnableClickEvent("NPlay",Me,"Play")
cl.setEnableClickEvent("NNext",Me,"Next")
Nbuild.Notify(1)
the code here is located inside the service create
B4X:
cl.Initialize("cm")
cl.SetImage("Image",LoadBitmap(File.DirDefaultExternal&"/AuxBitmaps",Cursor1.GetString("ID")&".png"))
    End If
 
    cl.SetTextField("Title",Cursor1.GetString("Title"))
    cl.SetTextField("Artist",Cursor1.GetString("Artist"))
    Nbuild.BigCustomLayout = cl.BuildLayout
    Nbuild.Notify(1)
and this code is called each time i select a new song and also inside a service sub.
 

barx

Well-Known Member
Licensed User
Longtime User
Where do you set your custom layout? And could you post your. Xml ?
 

barx

Well-Known Member
Licensed User
Longtime User
Will be a couple of hours before I get home to have a play
 

Mrjoey

Active Member
Licensed User
Longtime User
Where do you set your custom layout? And could you post your. Xml ?
B4X:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
     android:layout_width="match_parent"
    android:layout_height="140dp" >

    <ImageView
        android:id="@+id/Image"
        android:layout_width="140dp"
        android:layout_height="140dp"
        android:scaleType="fitXY" />

    <TextView
        android:id="@+id/Title"
        android:layout_width="match_parent"
        android:layout_height="40dp"
        android:layout_marginLeft="140dp"
        android:gravity="center_horizontal"
        android:text="Title"
        android:textSize="16sp"
        android:textStyle="normal|bold"
        android:typeface="serif" />

    <TextView
        android:id="@+id/Artist"
        android:layout_width="match_parent"
        android:layout_height="40dp"
        android:layout_marginLeft="140dp"
        android:layout_marginTop="40dp"
        android:gravity="center_horizontal"
        android:text="Artist"
        android:textSize="16sp"
        android:textStyle="bold"
        android:typeface="serif" />

    <Button
        android:id="@+id/Prev"
        android:layout_width="40dp"
        android:layout_height="20dp"
        android:layout_alignParentBottom="true"
        android:layout_marginBottom="2dp"
        android:layout_marginLeft="10dp"
        android:layout_toRightOf="@+id/Image"
        android:background="@drawable/btnprevious" />

    <Button
        android:id="@+id/Next"
        android:layout_width="40dp"
        android:layout_height="20dp"
        android:layout_alignParentBottom="true"
        android:layout_alignParentRight="true"
        android:layout_marginBottom="2dp"
        android:layout_marginRight="10dp"
        android:background="@drawable/btnnext" />

</RelativeLayout>
here is the xml , the file name is cm.xml , located inside "Objects\res\layout" and set to read-only , by the way i need to put a button between the prev and next buttons , i tried a lot bu failed to set it in the middle , i tried to put it inside a relative layout and set the button "android:layout_centerInParent="true" " but the app craches when adding another relative layout , anyway im thankfull
 

barx

Well-Known Member
Licensed User
Longtime User
Have a little look at the attached project to get an idea of how it works. As mentioned in the comments in the app, I will try to get time to update the lib to trigger a service when the item is clicked.

There were a couple of issues with your xml and also I removed the images as I simply didn't have the graphics.

The layout still needs work, but I didn't have time to mess with that. I'm no pro at xml layouts either. As mentioned before, probably better to get the xml from an existing app that has the desired layout.

Hope this helps
 

Attachments

  • Example.zip
    8 KB · Views: 512

Mrjoey

Active Member
Licensed User
Longtime User
thanks man , but i noticed that it works for activity but not service , and how to prevent closing the notification window when a button clicked , its annoying , i have an idea , instead of calling a intent , why not make a b4a event like this :
B4X:
ba.raiseEvent(null, eventName + "_Clicked", null);
isnt easy for u?and by this method u dont have to care anymore about if it was on a service or a activity both will work , and once again i appreciate ur help , and im here also to help improving this beautiful library , keep forward man
 

RonSens

Member
Licensed User
Longtime User
I have a question while using your library. it is working perfect and I am almost there.
But I noticed when using addaction to add buttons to the notification, the notification_tag is not available anymore in the intent.hasextras.
Only notification_action_tag is filled when clicking a button.
Is it possible to have both at the same time when I read the intent and take action on it?
Or is this possible in a way I do not know yet?

Thanks!
 

fbritop

Active Member
Licensed User
Longtime User
I cannot seem to make this library work.
It crashes when I call notify, with the next error:

java.lang.RuntimeException: Method: Notify not found in: barxdroid.NotificationBuilder.NotificationBuilder
 

barx

Well-Known Member
Licensed User
Longtime User
For both the above 2 posts, can you either post the relevant code or a small project demonstrating the issue, thanks
 

fbritop

Active Member
Licensed User
Longtime User
For both the above 2 posts, can you either post the relevant code or a small project demonstrating the issue, thanks
Barx:

B4X:
    Dim NB As NotificationBuilder
    NB.Initialize
    Dim nInbox As NotificationInboxStyle
    NB.SmallIcon="icon"
    NB.Ticker="New Demo"
    NB.Tag="SOME TAG"
    NB.setActivity(aMain)
    NB.DefaultLight=False
    NB.DefaultVibrate=False
    NB.DefaultSound=False
    NB.ContentTitle="Titulo"
    NB.ContentText="Contexto"
    NB.ContentInfo="INFO"
    NB.OnGoingEvent=True
    nInbox.Initialize
    nInbox.BigContentTitle="INBOX STYLE"
    nInbox.SummaryText="SUMMARY"
    NB.SetStyle(nInbox)
    NB.AddAction("arrow", "ABRIR", "TAG", aMain)
    NB.Notify(1)

Error thrown is:
Cannot get methods of class: barxdroid.NotificationBuilder.NotificationBuilder, disabling cache.
java.lang.RuntimeException: Method: setActivity not found in: barxdroid.NotificationBuilder.NotificationBuilder
at anywheresoftware.b4a.shell.Shell$MethodCache.getMethod(Shell.java:895)

Testing in a Samsung S4 Mini
 

barx

Well-Known Member
Licensed User
Longtime User
Works fine here using a full size S4. What version of NotificationBuilder do you have and do you have the latest support-v4 file?
 

Mrjoey

Active Member
Licensed User
Longtime User
hey , mr Barx , any updates?
 

barx

Well-Known Member
Licensed User
Longtime User
It is designed this way so you can differentiate between notification click or action click.
 

barx

Well-Known Member
Licensed User
Longtime User
hey , mr Barx , any updates?

Try this version. I have tweaked the EnableClickEvent() method to hopefully detect activity / service. Totally untested though lol.
 

Attachments

  • NotificationBuilderLibFilesV3.02.zip
    20.8 KB · Views: 344

Mrjoey

Active Member
Licensed User
Longtime User
Try this version. I have tweaked the EnableClickEvent() method to hopefully detect activity / service. Totally untested though lol.
Dont worry , it worked like a charm , one last request please , i need to set the play button visibility to false and true to display the pause drawable when playing songs and vice versa , i tried :
B4X:
Dim rv As RemoteViews
rv = cl.BuildLayout
rv.SetVisible(....)
but the compiler says that cl is a remoteviewwrapper and required a remoteviews .
can u make some alternatives to have the setvisible function works in some how? again thanks man for ur appreciated help.
 

barx

Well-Known Member
Licensed User
Longtime User


Try this one. See CustomLayout->SetVisibility

Again Untested....


Edit: broken file removed. see below
 
Last edited:
Cookies are required to use this site. You must accept them to continue using the site. Learn more…