0

I'm trying to use a custom layout for my Notification but without success so far. My layout file is the following :

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
          android:orientation="vertical"
          android:layout_width="match_parent"
          android:layout_height="match_parent">

<TextView
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:text="New Text"
    android:id="@+id/textView7"
    android:layout_gravity="center_horizontal"/>

`

and the code to display it is :

c=new Notification.Builder(this);
v=new RemoteViews(myPackage,R.layout.myLayoutFile);
c.setContent(v);        

((NotificationManager)getSystemService(NOTIFICATION_SERVICE).notify(2,c.build());

but no Notification appears in the status bar. If I use a standard layout (i.e I use setSmallIcon, setContentTitle and setContext to define mandatory elements), the Notification is correctly displayed.

What is wrong with my code?

This question has been marked as "duplicate". This is only partially true : nothing in the question mentionned as duplicate explains that my problem was not defining the small icon for the notification. Of Course, answers to the "original" question helped me discover I was missing the small icon definition for my Notificationbut it was not straightforward, and this question had to be presented to me while I was digging in the "stack" which, as far as I remember, didn't happen...

Zelig63
  • 1,592
  • 1
  • 23
  • 40
  • add notification builder code too? – Sohail Zahid Aug 08 '16 at 11:45
  • http://stackoverflow.com/a/18414768/5515371 Try this – Mujammil Ahamed Aug 08 '16 at 11:48
  • Duplicate question??!! I searched for a long time this morning and found nothing... If you mean the link just above (which I didn't see this morning certainly because it's title is not refering to custom layouts), the solution is probably the same : for a `Notification`, small icon is mandatory (and that's what was missing in my code) but content title and content text are useless, which is pretty normal because they don't appear with the custom layout... – Zelig63 Aug 08 '16 at 15:44

0 Answers0