Android的 - java.lang.IllegalArgumentException:如果contentIntent需要引起通知错误? [英] Android - java.lang.IllegalArgumentException: contentIntent required error caused by notification?

查看:169
本文介绍了Android的 - java.lang.IllegalArgumentException:如果contentIntent需要引起通知错误?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个更新的通知,在通知栏服务运行时,临危一条消息,必须改变。

I have a service running that updates a notification in the notification bar when it recieves a message saying it has to be changed.

不过我有时会收到以下错误时通知被更新

However I get the following error sometimes when the notification is to be updated

java.lang.IllegalArgumentException: contentIntent required

下面是我的code:

变量设置

int icon = R.drawable.notification;
CharSequence tickerText = "Test";
long when = System.currentTimeMillis();
PendingIntent contentIntent;

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

NotificationManager mNotificationManager;


NotificationManager创建


NotificationManager Creation

    String ns = Context.NOTIFICATION_SERVICE;
    mNotificationManager = (NotificationManager) getSystemService(ns);


通知单的创建


Notification Creation

    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);


通知的更新


Update of Notification

    notification.icon = R.drawable.notification2;
    notification.setLatestEventInfo(getApplicationContext(), "Registered", "Test", contentIntent);
    mNotificationManager.notify(1, notification);   


因此​​,一些地方正在发生的事情我contentIntent沿线,这是正确?


So something is happening my contentIntent somewhere along the line, would that be correct?

这是我的服务类的顶部为一个成员变量声明,不使用其他任何地方code除了如上图所示,那么,可以说,它是越来越重置为空?

It is declared at the top of my Service class as a member variable and is not used anywhere else in the code apart from shown above, so where could it be getting reset to null?

推荐答案

您需要设置contentIntent您的通知。

you need to set the contentIntent for your notification.

在你的情况:

notification.contentIntent = notificationIntent;

否则你会得到的消息,该通知的contentIntent是空的,因为它没有设置。

otherwise you will get the message, that the contentIntent of the notification is null, because it's not set.

实况是在这里:<一href="http://developer.android.com/reference/android/app/Notification.html#contentIntent">http://developer.android.com/reference/android/app/Notification.html#contentIntent

我有一个小例子在这里:<一href="http://united-$c$crs.com/nico-heid/show-progressbar-in-notification-area-like-google-does-when-downloading-from-android">http://united-$c$crs.com/nico-heid/show-progressbar-in-notification-area-like-google-does-when-downloading-from-android

i have a little example here: http://united-coders.com/nico-heid/show-progressbar-in-notification-area-like-google-does-when-downloading-from-android

这篇关于Android的 - java.lang.IllegalArgumentException:如果contentIntent需要引起通知错误?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆