zoukankan      html  css  js  c++  java
  • [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);

     

     

     

  • 相关阅读:
    浅析 KMP
    【GOJ 3049】玩具
    较详细的gdb入门教程
    【GOJ 2963】记者
    【GOJ 2961】数数
    GF OIer's Talk 维护笔记
    Linux 中 UFW 的使用
    开源是什么?能吃吗?
    个人介绍
    NOIP2020 爆零记
  • 原文地址:https://www.cnblogs.com/hpboy/p/3028085.html
Copyright © 2011-2022 走看看