0
正試圖在指定時間啓動intent以打開wifi,但由於某種原因報警立即觸發。我使用getTimeDifferenceas作爲參數調用setAlarm。我檢查了log.e和getTimeDifference返回的是準確的時間,但它仍然會觸發瞬間alarmManager在不等待指定時間的情況下觸發intent
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);
}
哦。非常感謝。 – user3789434
請記住upvote/accept。 –
我試了一下,但是它要求15以上的聲望哦,還有 – user3789434