Sending extras to BroadcastReceiver

后端 未结 3 1597
独厮守ぢ
独厮守ぢ 2021-01-15 01:07

I have an Activity that runs the following code (time and interval are defined):

Intent buzzIntent = new Intent(getBaseContext(), BuzzReceiver.class);
Pendin         


        
相关标签:
3条回答
  • 2021-01-15 01:16

    Have you tried calling buzzIntent.putExtra() before you pass buzzIntent to PendingIntent.getBroadcast()?

    0 讨论(0)
  • 2021-01-15 01:22

    Set flag FILL_IN_DATA while creating pending intent as below:

    PendingIntent pendingIntent = PendingIntent.getBroadcast(getBaseContext(), 0, buzzIntent, Intent.FILL_IN_DATA);
    

    You should receive extras in broadcast receiver after this change.

    0 讨论(0)
  • 2021-01-15 01:41

    Try following code

    Bundle bundle = intent.getExtras();
    int interval= bundle.getInt("interval", -1);
    

    instead of

    int interval = intent.getIntExtra("interval", -1);
    
    0 讨论(0)
提交回复
热议问题