错误的通知已发布-无法针对以下项展开RemoteViews:StatusBarNotification [英] Bad notification posted - Couldn't expand RemoteViews for: StatusBarNotification

查看:103
本文介绍了错误的通知已发布-无法针对以下项展开RemoteViews:StatusBarNotification的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图从IntentService在通知区域中发布具有自定义视图的通知,并出现Couldn't expand RemoteView错误.

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.

这是我在onCreate()中所做的事情:

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;

我正在从onHandleIntent()呼叫notify(),并取消onDestroy()中的通知.

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

我已验证此代码可在没有IntentService的独立应用程序中使用.在IntentService中执行此操作会给您带来麻烦.

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?

谢谢!

推荐答案

对我来说,问题是我在自定义通知视图xml文件中为根布局设置了特定的高度.

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

我更改后:

android:layout_height ="@ dimen/notification_expanded"

android:layout_height="@dimen/notification_expanded"

android:layout_height ="match_parent"

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.

这篇关于错误的通知已发布-无法针对以下项展开RemoteViews:StatusBarNotification的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆