我想爲我的應用程序創建一個新的調度器,每天在用戶定義的時間運行。下面是代碼。問題是,調度程序未在運行組建議time.Please如何做到這一點報警管理器不工作
private void setAlarm(String targetCal){
Toast.makeText(MainActivity.this,"Alarm Set", Toast.LENGTH_LONG).show();
String[] Time=targetCal.split(":");
Calendar timeOff = Calendar.getInstance();
Intent intent = new Intent(getBaseContext(), AlarmReceiver.class);
PendingIntent pendingIntent = PendingIntent.getBroadcast(getBaseContext(), RQS_1, intent, 0);
AlarmManager alarmManager = (AlarmManager)getSystemService(Context.ALARM_SERVICE);
//int days = Calendar.SUNDAY + (7 - timeOff.get(Calendar.DAY_OF_WEEK)); // how many days until Sunday
timeOff.set(Calendar.HOUR,Integer.valueOf(Time[0].trim()));
timeOff.set(Calendar.MINUTE,Integer.valueOf(Time[1].trim()));
alarmManager.setRepeating(AlarmManager.RTC_WAKEUP, timeOff.getTimeInMillis(), alarmManager.INTERVAL_DAY , pendingIntent);
}
timeOff.getTimeInMillis()會在當前時間告訴它。然後你問它在一天後的同一時間運行。你的目標是做什麼? – 2013-04-18 07:37:44
@ShobhitPuri目標是在設定的時間運行調度器 – Supreet 2013-04-18 07:39:47