My problem is that I get my video game release dates data from a third party api, and that third party api's dates are in milliseconds, when I use java's Calendar class to set my alarms, the alarm/notification gets called in the wrong time, what is the best way to set alarms in android so that they always get called at the correct time?
For example, the code I have now is weird. Game releases this Friday, I set an alarm for this game on Friday and this Thursday at 8pm Eastern, the alarm/notification gets fired. Why doesn't it fire at Friday midnight?
Here's my setAlarm method
/**
* Sets the next alarm to run. When the alarm fires,
* the app broadcasts an Intent to this WakefulBroadcastReceiver.
*/
public void setAlarm(Context context, Alarm alarm) {
AlarmManager alarmManager = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE);
// Passing our intent data
Intent alarmIntent = new Intent(context, AlarmReceiver.class);
alarmIntent.putExtra("releaseId", alarm.getReleaseID());
alarmIntent.putExtra("gameName", alarm.getGameName());
alarmIntent.putExtra("gameId", alarm.getGameId());
alarmIntent.putExtra("releaseDate", alarm.getDate());
alarmIntent.putExtra("type", alarm.getType());
// Note the release id is used here
String alarmId = String.valueOf(alarm.getReleaseID()) + getTypeId(alarm.getType());
PendingIntent pendingIntent = PendingIntent.getBroadcast(context, Integer.parseInt(alarmId), alarmIntent, PendingIntent.FLAG_UPDATE_CURRENT);
TimeZone timeZone = TimeZone.getTimeZone("UTC");
Calendar calendar = Calendar.getInstance(timeZone);
calendar.setTimeInMillis(alarm.getDate());
Date date = calendar.getTime();
alarmManager.set(AlarmManager.RTC_WAKEUP, date.getTime(), pendingIntent);
}