0

I'm trying to build a notification upon Android 2.3.3. I need a custom layout and I can't use Notification Builder. This is the layout of the notification:

R.layout.notification_upload

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:id="@+id/relative_notification_upload"
    android:layout_width="match_parent"
    android:layout_height="match_parent" >

    <ImageView
        android:id="@+id/imageview_icon"
        android:layout_height="match_parent"
        android:layout_marginRight="10dp"
        android:layout_centerVertical="true"
        android:src="@drawable/ic_launcher"
        android:contentDescription="@string/icon" >
    </ImageView>

    <ProgressBar
        android:id="@+id/progress_bar"
        style="@android:style/Widget.ProgressBar.Horizontal"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_centerHorizontal="true"
        android:layout_centerVertical="true"
        android:indeterminate="true" >
    </ProgressBar>

</RelativeLayout>

This is the code for the notification:

NotificationManager notificationManager = (NotificationManager) context
        .getSystemService(Context.NOTIFICATION_SERVICE);

Intent intent = new Intent(context, HomeActivity.class);
PendingIntent pendingIntent = PendingIntent.getActivity(context, 0,
        intent, 0);
RemoteViews contentView = new RemoteViews(context.getPackageName(), R.layout.notification_upload);

Notification notification = new Notification();

notification.when = 0;
notification.icon = R.drawable.ic_launcher;
notification.contentIntent = pendingIntent;
notification.contentView = contentView;

notificationManager.notify(0, notification);

I'm getting: Bad notification posted from package: couldn't expand RemoteViews for... Where am I getting wrong? Can I use ImageView inside notification?

Jumpa
  • 4,319
  • 11
  • 52
  • 100
  • what is your RemoteViews ? – Piyush Feb 12 '14 at 15:12
  • It's the layout I posted above, an imageview with a progress bar. – Jumpa Feb 12 '14 at 15:13
  • Its the name of Layout? – Piyush Feb 12 '14 at 15:14
  • The RemoteViews uses R.layout.notification_upload layout: http://developer.android.com/reference/android/widget/RemoteViews.html – Jumpa Feb 12 '14 at 15:16
  • what is your minimum sdk version? – Piyush Feb 12 '14 at 15:20
  • That's why. It is not applicable for api level < 11 – Piyush Feb 12 '14 at 15:22
  • What in particular? The ImageView? 'cause if I remove it from the layout, the remaining progress bar is correctly displayed. I'd like to have an icon like this: http://edumobile.org/android/wp-content/uploads/2011/03/NotificationExample5.jpg. Here http://stackoverflow.com/questions/10607097/how-to-add-vertical-line-to-remoteview-for-custom-android-notifications the post says that ImageView is supported... – Jumpa Feb 12 '14 at 15:25

0 Answers0