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?
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.
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 :)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With