我有一个正在运行的服务,当它收到一条通知必须更改的消息时,它会更新通知栏中的通知。
但是,当要更新通知时,我有时会收到以下错误
java.lang.IllegalArgumentException: contentIntent required
下面是我的代码:
变量设置
int icon = R.drawable.notification;
CharSequence tickerText = "Test";
long when = System.currentTimeMillis();
PendingIntent contentIntent;
Notification notification = new Notification(icon, tickerText, when);
NotificationManager mNotificationManager;
NotificationManager创建
String ns = Context.NOTIFICATION_SERVICE;
mNotificationManager = (NotificationManager) getSystemService(ns);
通知创建
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);
更新通知
notification.icon = R.drawable.notification2;
notification.setLatestEventInfo(getApplicationContext(), "Registered", "Test", contentIntent);
mNotificationManager.notify(1, notification);
因此,我的contentIntent在这条线上的某个地方发生了一些事情,对吗?
它在我的Service类的顶部声明为成员变量,并且除了上面显示的之外,不会在代码中的其他任何地方使用,那么在哪里可以将它重置为null?
发布于 2010-09-13 23:39:11
您需要设置通知的contentIntent。
在您的案例中:
notification.contentIntent = notificationIntent;
否则,您将收到通知的contentIntent为空的消息,因为它没有被设置。
文档在这里:http://developer.android.com/reference/android/app/Notification.html#contentIntent
发布于 2013-06-16 05:26:11
在我的例子中,我有一个示例代码要做,只需要创建一个通知,而且我还得到了"contentIntent required“错误-谷歌将我带到了这个线程:D
这个问题的根源是我从一个示例代码中复制的引文,并将其粘贴到eclipse项目中。当我删除“”并重新键入它们时,问题就解决了。也许这对某些人有帮助。
以下是错误的引用来源:nb.setContentTitle(“我的第一个通知!”);nb.setContentText("Hello");
https://stackoverflow.com/questions/3112008
复制相似问题