Intent.putExtras doesn't match
I have a strange situation with AlarmManager. I am scheduling an event with AlarmManager and passing a string using aim.putExtra. The line is either silent or vibrating, and when the receiver is triggered, the phone must either turn on the ringer or set the phone to vibrate. The log statement correctly outputs the expected value every time.
Intent intent;
if (eventType.equals("start")) {
intent = new Intent(context, SReceiver.class);
} else {
intent = new Intent(context, EReceiver.class);
}
intent.setAction(eventType+Long.toString(newId));
Log.v("EditQT",ringerModeType.toUpperCase());
intent.putExtra("ringerModeType", ringerModeType.toUpperCase());
PendingIntent appIntent = PendingIntent.getBroadcast(context, 0,
intent, 0);
AlarmManager alarmManager = (AlarmManager) getSystemService (Context.ALARM_SERVICE);
alarmManager.set(AlarmManager.RTC_WAKEUP, calendar.getTimeInMillis(),
appIntent);
The receiver that fires when the alarm is executed also has a log statement, and I see the first time the statement outputs the expected SILENT or VIBRATE string, but for each subsequent execution, the output shows the original value at the receiver end, The alarm is executed and then I change the value for putExtra to the opposite line and the receiver still displays the previous value event, although the call from the above code shows that a new value has been passed. The value for setAction is the same every time.
audioManager = (AudioManager) context.getSystemService(Activity.AUDIO_SERVICE);
Log.v("Start",intent.getExtras().get("ringerModeType").toString());
if (intent.getExtras().get("ringerModeType").equals("SILENTMODE")) {
audioManager.setRingerMode(AudioManager.RINGER_MODE_SILENT);
} else {
audioManager.setRingerMode(AudioManager.RINGER_MODE_VIBRATE);
}
Any thoughts?
a source to share
Your question was asked six hours ago .
If you have several PendingIntents
at the same time with different settings, you will need to change something else in Intents
, like the action bar or Uri
as described in the linked issue above.
If you only have one PendingIntent
at a time, but your additional may be different, just use FLAG_UPDATE_CURRENT
in your reference to getBroadcast()
.
a source to share