intent.putExtra() in pending intent not working

后端 未结 5 722
你的背包
你的背包 2021-02-02 08:25

I am passing a pending intent through alarmreceiver, from a service class. But, after the pendingIntent fires, the intent.putExtra() information is not being received by the bro

5条回答
  •  梦谈多话
    2021-02-02 08:57

    You have to use getStringExtra() and be sure the String are not null:

         Intent intent = getIntent();    
         msg = intent.getStringExtra("msg");
         phonen = intent.getStringExtra("phone");
    
         if(msg!=null){
          Toast.makeText(context,msg,
            Toast.LENGTH_LONG).show();
         }
    

    and reverse Your putExtras before PendingIntent:

       Intent aint = new Intent(getApplicationContext(), AlarmReceiver.class);
       aint.putExtra("msg", msg);
       aint.putExtra("phone", phone);
       PendingIntent pendingIntent = PendingIntent.getBroadcast(getApplicationContext(), id, aint, PendingIntent.FLAG_UPDATE_CURRENT);
    

提交回复
热议问题