Android - java.lang.IllegalArgumentException: contentIntent required error caused by notification?

后端 未结 4 2251
北荒
北荒 2021-02-19 00:52

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 so

4条回答
  •  执笔经年
    2021-02-19 01:19

    In your case

    contentIntent = PendingIntent.getActivity(this, 0, notificationIntent,0);
    

    if you want to use Intents with the same action but different extras:

    1. Change requestCode from default "0" in

      getActivity(Context context, int requestCode, Intent intent, int flags)
      

    to something unique like

    (int) System.currentTimeMillis();
    
    notification.contentIntent = notificationIntent;
    

    Both steps are mandatory because:

    • Option 2 will not work without option 1.
    • Option 1 will throw IllegalArgumentException without 2.

提交回复
热议问题