簡體   English   中英

alarmManager在不等待指定時間的情況下觸發意圖

[英]alarmManager fires intent without waiting for specified time

我試圖在指定的時間啟動意圖以打開wifi,但由於某種原因,警報立即觸發。 我用getTimeDifference作為參數調用setAlarm。 我檢查了log.e和getTimeDifference返回的時間是准確的,但仍會立即觸發

   public long getTimeDifference(){
    Date current = new Date();
    Date future = new Date();
    future.setHours(time.getCurrentHour());
    future.setMinutes(time.getCurrentMinute());
    if((future.getTime() - current.getTime()) < 0){
        future.setDate(future.getDate()+1);
    }
    return  future.getTime() - current.getTime();
}
public void setAlarm(long time){
    Intent intent = new Intent(Volume.this,RadioService.class);
    PendingIntent pendingIntent = pendingIntent = PendingIntent.getService(
            Volume.this, 0, intent, 0);
    String sd = "time is:" + time;
    Log.e("time dif", sd);
    alarm.set(AlarmManager.RTC_WAKEUP, time, pendingIntent);
}

RTC_WAKEUP希望使用UTC的實際時間,而不是差值。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM