Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/230.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java alarmManager在不等待指定时间的情况下激发意图_Java_Android - Fatal编程技术网

Java alarmManager在不等待指定时间的情况下激发意图

Java alarmManager在不等待指定时间的情况下激发意图,java,android,Java,Android,我正试图在指定的时间开启wifi,但由于某些原因,警报会立即响起。我使用getTimeDifferenceas作为参数调用setAlarm。我检查了log.e和getTimeDifference返回的时间是否准确,但它仍然会立即触发 public long getTimeDifference(){ Date current = new Date(); Date future = new Date(); future.setHours(time.getCurrentH

我正试图在指定的时间开启wifi,但由于某些原因,警报会立即响起。我使用getTimeDifferenceas作为参数调用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);
}
public long getTimeDifference(){
当前日期=新日期();
未来日期=新日期();
future.setHours(time.getCurrentHour());
future.setMinutes(time.getCurrentMinutes());
如果((future.getTime()-current.getTime())<0){
future.setDate(future.getDate()+1);
}
返回future.getTime()-current.getTime();
}
公共无效设置报警(长时间){
意向意向=新意向(Volume.this,RadioService.class);
pendingent pendingent=pendingent=pendingent.getService(
卷。本,0,意图,0);
String sd=“时间是:”+时间;
Log.e(“时间dif”,sd);
alarm.set(AlarmManager.RTC_唤醒、时间、挂起内容);
}

RTC_WAKEUP
想要的是UTC的实际时间,而不是差值