2

我正在使用以下代码在onRecievemy 的方法中创建通知,BroadcastReceiver但它给了我以下异常:

java.lang.IllegalArgumentException: contentIntent required

编码:

 NotificationManager notificationManager;
        notificationManager = (NotificationManager) context
                .getSystemService(Context.NOTIFICATION_SERVICE);
    String tickerText;
    String expandedText;
    String expandedTitle;
    int icon;
    long when;
    Notification notification;

    int notificationref = new Random().nextInt(100) + 1;
    icon = R.drawable.reminder;
    tickerText = "New Reminder";
    when = System.currentTimeMillis();
    notification = new Notification(icon, tickerText, when);
    expandedText = "Reminder at: "
            + DateOrTimeString.getTimeString(task.time) + "\n"
            + task.detail;
    expandedTitle = "Reminder:" + task.topic;
    Intent intentDestroyer = new Intent(context, RemindHomeActivity.class);
    intentDestroyer.putExtra("ID", task.id);
    intentDestroyer.putExtra("NOTIFICATIONREF", notificationref);
    launchIntent = PendingIntent.getActivity(context, notificationref,
            intentDestroyer, 0);

    notification.setLatestEventInfo(mContext, expandedTitle, expandedText,
            null);
    notificationManager.notify(1, notification);

还有一件事这个问题只在 API 级别小于 11。它在 API 级别 15 Icecream Sandwitch 中工作

4

1 回答 1

0

您需要设置 contentIntent

void android.app.Notification.setLatestEventInfo(Context context, CharSequence contentTitle, CharSequence contentText, PendingIntent contentIntent)‬

在你的情况下:

notification.setLatestEventInfo(mContext, expandedTitle, expandedText,
            launchIntent );
于 2013-03-12T04:32:44.027 回答