2013-04-16 15 views
1

我想創建一個Android的應用程序的調度中,我想在一個指定的time.Below每天在後臺運行的應用程序是代碼,但是這不是爲我工作請建議如何在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); 

} 
+0

嘗試System.getTimeInMillis()而不是timeoff.getTimeInMillis() – Senthil

回答

0

我不能根據你的描述確定它不起作用的原因,但我的猜測是你沒有獲得AlarmReceiver的的onReceive()方法。

前段時間我發佈了a similar question,而我試圖實現類似的東西。查看CommonsWare公認的答案和答案。我希望他們在解決你的問題方面有用。

問候!