我正在运行一项服务,当它收到一条表示必须更改的消息时,它会更新通知栏中的通知。
但是,当要更新通知时,有时会出现以下错误
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;
通知管理器创建
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 呢?