Android Question Need help building custom notification like this.

Mrjoey

Active Member
Licensed User
Longtime User
hello i need to build a notification layout like seen in the attached picture , i see different libraries on the forum like "Custom Notification Library: Barx" but does not support buttons , is there a way to create such layout? thanks
 

Attachments

  • Screenshot_2014-10-13-14-33-06.png
    Screenshot_2014-10-13-14-33-06.png
    169.1 KB · Views: 378

Mrjoey

Active Member
Licensed User
Longtime User
can u give me some tips on where to start please mr erel?
schould first build a xml layout right? say 3 buttons , 1 imageview , 2 texts , and then what? how to access them , schould i create click events for them inside my activity?or service? can u explain more please? thank u
 
Upvote 0

barx

Well-Known Member
Licensed User
Longtime User
If you wish for it look exactly like that, then yes you will need to build a custom layout in xml. If you only need 3 buttons and don't mind compromising the look slightly to make the job a lot easier you could use Actions. I will try to offer a bit more help in a few hours (at work at moment just checking forum every now and again).
 
Upvote 0

Mrjoey

Active Member
Licensed User
Longtime User
If you wish for it look exactly like that, then yes you will need to build a custom layout in xml. If you only need 3 buttons and don't mind compromising the look slightly to make the job a lot easier you could use Actions. I will try to offer a bit more help in a few hours (at work at moment just checking forum every now and again).
Thank u Mr barx , appreciate ur help , im waiting , best regards :)
 
Upvote 0

barx

Well-Known Member
Licensed User
Longtime User
Ok, it turned out to be a long day at work so I don't have a lot of time (need to get to bed for tomorrow's early start ;)). Here is some thoughts to get you started.

If you haven't already, then download the notificationBuilder demo app and fire a notification with Style: BigPictureStyle and 'Add Actions'. This is what it will look like for the compromise.

The other option to make it look exactly like your sample is, as stated, create an xml layout. Look at the NotificationCustomLayout object. You specify your layout file in the .initialize method and can use setEnableClickEvent to add click events to the buttons (or any other views in notification ;))

Note I have tested this extensively but my brief tests work well so it should be ok.

As stated above by @Erel , the library (and demo app) can be found here

Sorry I don't have much time tonight. Feel free to ask any questions and I will try to answer best I can whilst at work tomorrow....
 
Upvote 0

Mrjoey

Active Member
Licensed User
Longtime User
hey mr Barx , i really appreciate that u make time for us even though ur very busy , but here some questions:
i have installed ur app and did some tests , i copied the code from ur app ("code to build...") for bigpicturetype
B4X:
Nbuild.Initialize
Nbuild.SmallIcon = "icon"
Nbuild.OnGoingEvent = True
Nbuild.setActivity(Main)
Nbuild.Notify(1)
Nuild is notification builder
this code is written inside Service_Create and when my app starts it forces close with this error
** Activity (main) Create, isFirst = true **
** Activity (main) Resume **
** Service (bs) Create **
** Service (bs) Start **
java.lang.NoClassDefFoundError: android.support.v4.app.NotificationManagerCompat
at barxdroid.NotificationBuilder.NotificationBuilder.Notify(NotificationBuilder.java:512)
at a.mp.bs._service_start(bs.java:1184)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:511)
at anywheresoftware.b4a.BA.raiseEvent2(BA.java:175)
at anywheresoftware.b4a.BA.raiseEvent(BA.java:159)
at a.mp.bs.handleStart(bs.java:68)
at a.mp.bs.onStartCommand(bs.java:53)
at android.app.ActivityThread.handleServiceArgs(ActivityThread.java:2531)
at android.app.ActivityThread.access$1900(ActivityThread.java:140)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1324)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:137)
at android.app.ActivityThread.main(ActivityThread.java:4898)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:511)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1006)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:773)
at dalvik.system.NativeStart.main(Native Method)
the android-support-4.jar is copied into libraries folder.
the second question is
i had already used the standard notification and using
B4X:
Sub Service_Start (StartingIntent As Intent)
Service.StartForeground(1,n)

End Sub
im afraid if i used ur library my service wont be in the foreground , im sry im new notifications , and i appreciate ur passions , thank u.
 
Upvote 0

Straker

Active Member
Licensed User
Longtime User
I think that you should download the v4 support jar
 
Upvote 0

barx

Well-Known Member
Licensed User
Longtime User
As straker has stated. You need the Android support v4 library. Download it with Android sdk manager and then copy to your additional libraries folder. It's all in the installation section of my library's documentation ;)
 
Upvote 0

Mrjoey

Active Member
Licensed User
Longtime User
thnx guys for ur help , i just downloaded the android-support jar revision 20 and it solves the problem.
i just uploaded a pic showing bigpicturestyle , its pretty good so far , now i will mess around with custom layout and here some questions:
where would have to put the xml file to load via "NotificationCustomLayout.Initialize(layoutfile)"?
is possible to hide or disable the icon? i mean if u look at the previous pic u notice that there is no icon.
can u provide me a small example about writing the xml code?
can buttons have statelist drawable? thank u.
 

Attachments

  • Screenshot_2014-10-14-17-31-06.png
    Screenshot_2014-10-14-17-31-06.png
    401.4 KB · Views: 190
Upvote 0

Mrjoey

Active Member
Licensed User
Longtime User
B4X:
<?xml version="1.0" encoding="utf-8"?>

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/layout"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:padding="10dp" >
    <ImageView android:id="@+id/image"
        android:layout_width="wrap_content"
        android:layout_height="fill_parent"
        android:layout_alignParentLeft="true"
        android:layout_marginRight="10dp" />
    <TextView android:id="@+id/title"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_toRightOf="@id/image" />
    <TextView android:id="@+id/text"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_toRightOf="@id/image"
        android:text="Type here:"
        android:layout_below="@id/title" />
</RelativeLayout>

if i want to start from this layout :
what is padding?layout_marginRight?
if i want to add 3 buttons with statelist drawable , how to setup them?
 
Upvote 0

barx

Well-Known Member
Licensed User
Longtime User
Put your layout in the 'project/res/layout/' dir and set the xmls file(s) as read only.

The above layout looks like it will create a notification very similar to the default notification. The padding is to create some space around the edge of the layout.
 
Upvote 0
Top