我正在尝试在android中创建一个调度程序应用程序,我想在指定的时间每天在后台运行应用程序。下面是代码,但这对我不起作用请建议
private void setAlarm(String targetCal){
String[] Time=targetCal.split(":");
Intent intent = new Intent(getBaseContext(), AlarmReceiver.class);
PendingIntent pendingIntent = PendingIntent.getBroadcast(getBaseContext(), RQS_1, intent, 0);
AlarmManager alarmManager = (AlarmManager)getSystemService(Context.ALARM_SERVICE);
Calendar timeOff = Calendar.getInstance();
//int days = Calendar.SUNDAY + (7 - timeOff.get(Calendar.DAY_OF_WEEK)); // how many days until Sunday
timeOff.set(Calendar.HOUR,Integer.valueOf(Time[0]));
timeOff.set(Calendar.MINUTE,Integer.valueOf(Time[1]));
timeOff.set(Calendar.SECOND, 00);
alarmManager.setRepeating(AlarmManager.RTC_WAKEUP, timeOff.getTimeInMillis(), 24*60*60*1000 , pendingIntent);
}