发布了错误通知 - 无法为以下内容展开 RemoteViews:StatusBarNotification [英] Bad notification posted - Couldn't expand RemoteViews for: StatusBarNotification

查看:27
本文介绍了发布了错误通知 - 无法为以下内容展开 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天全站免登陆