我想每天在特定時間發送廣播。我寫了一些代碼,但日曆返回錯誤的日期,廣播做了無限循環。我做錯了什麼?如何在AlarmManager中設置PendingIntent一段特定時間?
Boolean static1Active = prefs.getBoolean("static_switch1", true);
Log.i("HHG", "Static1? " + (INTENT_TYP.equals("static1") && static1Active));
if(INTENT_TYP.equals("static1") && static1Active){
String check_time1 = prefs.getString("check_time1", "6:0");
String[] pieces=check_time1.split(":");
Integer hour = Integer.parseInt(pieces[0]);
Integer minute = Integer.parseInt(pieces[1]);
Calendar calendar = Calendar.getInstance();
calendar.set(Calendar.YEAR, Calendar.MONTH, Calendar.DATE, hour, minute);
Log.i("HHG","Calendar: " +calendar.getTime());
Intent static1 = new Intent(context, VertretungCheck.class);
static1.putExtra("typ", "static1");
PendingIntent pendingIntent = PendingIntent.getBroadcast(context, 1, static1, PendingIntent.FLAG_UPDATE_CURRENT);
AlarmManager alarmManager = (AlarmManager)context.getSystemService(Context.ALARM_SERVICE);
alarmManager.set(AlarmManager.RTC_WAKEUP, calendar.getTimeInMillis(), pendingIntent);
}
我知道,但我想它會自動設定當前日期,如果不工作,我需要檢查當天... – Grevius