[BUG记录]java.lang.IllegalArgumentException: contentIntent required

今天遇到一个异常,在notificationManager.notify的时候发生java.lang.IllegalArgumentException: contentIntent required,原因是我个没有设置contentIntent。

以前一直在4.0的机子上跑是没有问题的,在2.3、2.2上就会出现异常。

所以还是要设置contentIntent,只是Intents设置不同的动作,contentIntent不可以设为空!!!

例如:

 

        NotificationManager mNotifMgr = (NotificationManager)cn.getSystemService(Context.NOTIFICATION_SERVICE); 
        CharSequence title = cn.getString(R.string.app_name);
        Notification notify = new Notification(R.drawable.ic_launcher, message, System.currentTimeMillis());
        notify.flags |= Notification.FLAG_AUTO_CANCEL;
        
        //跳转的页面,且设置如果当前已经打开了,就是用当前这个。//FLAG_UPDATE_CURRENT 
        //Intent notifyIntent = new Intent(this, cn.getClass());
        //notifyIntent.addFlags(android.content.Intent.FLAG_ACTIVITY_SINGLE_TOP);
        //notifyIntent.addFlags(android.content.Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED);
        PendingIntent pendingintent = PendingIntent.getActivity(cn, 0, new Intent(), PendingIntent.FLAG_CANCEL_CURRENT);
        notify.setLatestEventInfo(cn, title, message, pendingintent);
        mNotifMgr.notify(notifyId, notify);

 

 

 

 

posted on 2013-04-18 11:29  Android最前线  阅读(2102)  评论(0编辑  收藏  举报