3

I need your help! When I put extras in my Intent and then I use that Intent to create a Pending Intent it doesn't work! I don't enter to the BroadCastReceiver class.

public class Recordatori_Visita extends Activity {
    public void setAlarm(Calendar targetCal) {

        Intent intent = new Intent (Recordatori_Visita.this, Receiver.class);
        Long targetCal2 = targetCal.getTimeInMillis();  
        intent.putExtra("targetCal",targetCal2);
        intent.putExtra("n",n);
        PendingIntent pendingIntent = PendingIntent.getBroadcast(Recordatori_Visita.this, 1, intent, intent.FILL_IN_DATA);

        AlarmManager alarmManager = (AlarmManager)getSystemService(ALARM_SERVICE);
        alarmManager.set(AlarmManager.RTC_WAKEUP, targetCal.getTimeInMillis(),pendingIntent);
    }
}

.

public class Receiver extends BroadcastReceiver {

    @Override
    public void onReceive(Context k1, Intent k2) {
    // TODO Auto-generated method stub 

        Bundle bolsaR = k2.getExtras();
        Long extras = bolsaR.getLong("targetCalKey");
        int n= bolsaR.getInt("n");

        NotificationManager notificationManager = (NotificationManager) k1.getSystemService(Context.NOTIFICATION_SERVICE);
        ...
        notificationManager.notify(1,myNotification);

   }
}

I've cut the code, all the variables used are created, I can't find the solution. If I don't put extra data in the intent it works fine but when I putExtra it doesn't work because there is no notification. Thanks!!

Alzamora12
  • 31
  • 2
  • Check it. http://stackoverflow.com/questions/3127957/why-the-pendingintent-doesnt-send-back-my-custom-extras-setup-for-the-intent – Ahmad Raza Nov 08 '13 at 10:50
  • Probably not an answer to your question, but the parameter `intent.FILL_IN_DATA` on the call to `getBroadcast()` is totally wrong. That parameter is for `PendingIntent` flags. What are you trying to do there? – David Wasser Nov 08 '13 at 19:13
  • Are you saying that `onReceive()` is not called if you have extras in the `Intent`? Are you sure? Have you added logging in `onReceive()`? – David Wasser Nov 08 '13 at 19:16

1 Answers1

0

try putting the System time as the requestCode in the getBroadcast() function.

int requestID = (int) System.currentTimeMillis();
PendingIntent pendingIntent = PendingIntent.getBroadcast(Recordatori_Visita.this, requestID, intent, intent.FILL_IN_DATA);
droidx
  • 2,172
  • 19
  • 26