Bad notification posted - Couldn't expand RemoteViews for: StatusBarNotification

Chaitanya picture Chaitanya · Jun 2, 2011 · Viewed 40.6k times · Source

I am trying to post a notification with a custom view in the notification area from an IntentService, and getting the Couldn't expand RemoteView error.

Here's what I am doing in onCreate():

mNotificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
icon = R.drawable.icon;
tickerText = "data upload in progress";
contentView = new RemoteViews(getApplicationContext().getPackageName(), R.layout.notiflayout);
contentView.setImageViewResource(R.id.image, R.drawable.icon);
contentView.setTextViewText(R.id.text, "Hello");
contentView.setProgressBar(R.id.progressBar, 100, 10, false);
whatNext = PendingIntent.getActivity(getApplicationContext(), 0, new Intent(getApplicationContext(), starterActivity.class), 0);
notification = new Notification(icon, tickerText, System.currentTimeMillis());
notification.contentView = contentView;
notification.contentIntent = whatNext;

I am calling notify() from onHandleIntent(), and canceling the notifications in onDestroy().

I have verified that this code works in an independent app, which does not have an IntentService. Doing this in an IntentService is somehow giving trouble.

Could someone please explain what is it that I am doing wrong?

Thanks!

Answer

Iman Akbari picture Iman Akbari · Jun 2, 2015

For me, the problem was that I was setting a specific height for the root layout, in the custom notification view xml file.

As soon as I changed:

android:layout_height="@dimen/notification_expanded"

to

android:layout_height="match_parent"

in the root layout of notification view, the problem was solved.

Also take a look at this example to see a simple example of using custom layout for notifications.