Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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?

like image 999
Chaitanya Avatar asked Jun 02 '11 01:06

Chaitanya


2 Answers

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.

like image 148
Iman Akbari Avatar answered Oct 08 '22 14:10

Iman Akbari


for unknown reason you are not allowed to reference dimention in the root view of the custom remote view! so you have to hard code it like android:layout_height="64dp" but if you used android:layout_height="@dimen/notification_height_that_64" it will give you Bad notification posted - Couldn't expand RemoteViews for: StatusBarNotification . i hope this will help :)

like image 21
M_AWADI Avatar answered Oct 08 '22 15:10

M_AWADI