错误的通知已发布-无法针对以下项展开RemoteViews:StatusBarNotification [英] Bad notification posted - Couldn't expand RemoteViews for: 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屋!