I have an xml file defined as follows:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:gravity="center"
android:orientation="horizontal" >
<EditText
android:id="@+id/view1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="notif"
/>
<Button
android:id="@+id/button1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Send" />
</LinearLayout>
I am trying to add this xml file to a notification and this is what I have so far:
RemoteViews remoteViews = new RemoteViews(context.getPackageName(),
R.layout.custom_layout);
NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(
context).setSmallIcon(R.drawable.ic_launcher).setContent(
remoteViews);
// Creates an explicit intent for an Activity in your app
Intent resultIntent = new Intent(context, Receiver.class);
TaskStackBuilder stackBuilder = TaskStackBuilder.create(context);
stackBuilder.addNextIntent(resultIntent);
PendingIntent resultPendingIntent = stackBuilder.getPendingIntent(0,
PendingIntent.FLAG_UPDATE_CURRENT);
remoteViews.setOnClickPendingIntent(R.id.button1, resultPendingIntent);
NotificationManager mNotificationManager = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
// mId allows you to update the notification later on.
mNotificationManager.notify(100, mBuilder.build());
But when I try to add it like this, I get the error "Bad notification posted from package [package name]. Couldn't expand RemoteViews"
Can someone tell me what I am doing wrong here. Thanks!
RemoteView
's layout does not supportEditText
. Try replacing it with aTextView
.You can refer to this list for views/layouts supported by
RemoteView
Hope that helps