这里我使用闹钟管理器在特定时间拨打电话。我想在23:59:00拨打该服务。如何在特定时间呼叫报警管理器?请帮我解决这个问题。
Calendar calendar=Calendar.getInstance();
calendar.add(Calendar.SECOND,what time to set);
Intent intent=new Intent(getApplicationContext(),StartServiceAlaramReceiver.class);
startAlaramServicePendingIntent=PendingIntent.getBroadcast(getApplicationContext(),0, intent,PendingIntent.FLAG_UPDATE_CURRENT);
AlarmManager alarmManager=(AlarmManager)getSystemService(ALARM_SERVICE);
alarmManager.set(AlarmManager.RTC_WAKEUP,calendar.getTimeInMillis(),startAlaramServicePendingIntent);
答案 0 :(得分:1)
我发现使用JodaTime库来处理日期和时间方面的任何事情。
Intent intent=new Intent(getApplicationContext(),StartServiceAlaramReceiver.class);
startAlaramServicePendingIntent=PendingIntent.getBroadcast(getApplicationContext(),0, intent,PendingIntent.FLAG_UPDATE_CURRENT);
final DateTime todayE = (new DateTime()).minuteOfDay().withMaximumValue().minusMinutes(1);
AlarmManager alarmManager=(AlarmManager)getSystemService(ALARM_SERVICE);
alarmManager.set(AlarmManager.RTC_WAKEUP,todayE.getMillis(),startAlaramServicePendingIntent);
答案 1 :(得分:1)
U可以使用以下方式为alarmmanager提供时间,
Intent activate = new Intent(this, AlaramActivity.class);
AlarmManager alarams ;
PendingIntent alarmIntent = PendingIntent.getBroadcast(this, 0, activate, 0);
alarams = (AlarmManager) getSystemService(ALARM_SERVICE);
alarams.set(AlarmManager.RTC_WAKEUP, cal.getTimeInMillis()+5000, alarmIntent);
答案 2 :(得分:0)
以下链接提供详细说明,以设置将在指定时间触发的事件。 http://justcallmebrian.com/?p=129