Android AlarmManager set function doesn't work?
I want to add an alarm, so I used the following code:
public void SetAlarm(Alarm alarm)
{
mTimeTarget = PendingIntent.getBroadcast(mContext, alarm.getRowID(),
new Intent(HomeScreen.ACTION_CHECK_TIME_ALARMS), PendingIntent.FLAG_UPDATE_CURRENT);
mAlarmManager.set(AlarmManager.ELAPSED_RE开发者_开发问答ALTIME_WAKEUP, alarm.getAlarmTime().toMillis(true), mTimeTarget);
}
But this doesn't seem to work. (I tried on the emulator, and when the time comes, nothing happens - my onReceive function on my class that extends BroadcastReceiver isn't called).
Here is how I initialized mAlarmManager on the constructor (it is private because this class is singleton):
private AlarmsManager(Context con)
{
mContext = con;
mAlarmManager = (AlarmManager) con.getSystemService(Context.ALARM_SERVICE);
}
Any idea what I did wrong? Thanks!
Perhaps alarm.getAlarmTime().toMillis(true)
is not in the timebase of SystemClock.elapsedRealtime()
. If getAlarmTime()
returns a android.text.format.Time
object, this is most certainly incorrect.
精彩评论