首页
学习
活动
专区
工具
TVP
发布
社区首页 >问答首页 >Android - java.lang.IllegalArgumentException:通知导致contentIntent必需错误?

Android - java.lang.IllegalArgumentException:通知导致contentIntent必需错误?
EN

Stack Overflow用户
提问于 2010-06-25 00:41:45
回答 2查看 15.9K关注 0票数 18

我有一个正在运行的服务,当它收到一条通知必须更改的消息时,它会更新通知栏中的通知。

但是,当要更新通知时,我有时会收到以下错误

代码语言:javascript
复制
java.lang.IllegalArgumentException: contentIntent required

下面是我的代码:

变量设置

代码语言:javascript
复制
int icon = R.drawable.notification;
CharSequence tickerText = "Test";
long when = System.currentTimeMillis();
PendingIntent contentIntent;

Notification notification = new Notification(icon, tickerText, when);

NotificationManager mNotificationManager;

NotificationManager创建

代码语言:javascript
复制
    String ns = Context.NOTIFICATION_SERVICE;
    mNotificationManager = (NotificationManager) getSystemService(ns);

通知创建

代码语言:javascript
复制
    Intent notificationIntent = new Intent(this, TestsApp.class);
    contentIntent = PendingIntent.getActivity(this, 0, notificationIntent, 0);
    notification.flags |= Notification.FLAG_NO_CLEAR;
    notification.icon = R.drawable.notification3;
    notification.setLatestEventInfo(this, "Registering", "Test", contentIntent);
    mNotificationManager.notify(1, notification);

更新通知

代码语言:javascript
复制
    notification.icon = R.drawable.notification2;
    notification.setLatestEventInfo(getApplicationContext(), "Registered", "Test", contentIntent);
    mNotificationManager.notify(1, notification);   

因此,我的contentIntent在这条线上的某个地方发生了一些事情,对吗?

它在我的Service类的顶部声明为成员变量,并且除了上面显示的之外,不会在代码中的其他任何地方使用,那么在哪里可以将它重置为null?

EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2010-09-13 23:39:11

您需要设置通知的contentIntent。

在您的案例中:

代码语言:javascript
复制
notification.contentIntent = notificationIntent;

否则,您将收到通知的contentIntent为空的消息,因为它没有被设置。

文档在这里:http://developer.android.com/reference/android/app/Notification.html#contentIntent

这里有一个小示例:http://united-coders.com/nico-heid/show-progressbar-in-notification-area-like-google-does-when-downloading-from-android

票数 15
EN

Stack Overflow用户

发布于 2013-06-16 05:26:11

在我的例子中,我有一个示例代码要做,只需要创建一个通知,而且我还得到了"contentIntent required“错误-谷歌将我带到了这个线程:D

这个问题的根源是我从一个示例代码中复制的引文,并将其粘贴到eclipse项目中。当我删除“”并重新键入它们时,问题就解决了。也许这对某些人有帮助。

以下是错误的引用来源:nb.setContentTitle(“我的第一个通知!”);nb.setContentText("Hello");

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/3112008

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档