我正在構建報警應用程序。爲此,我需要提供一個時間作爲輸入。我正在嘗試下面的代碼,但報警不會觸發。我在網上搜索並修改了很多代碼,但仍然沒有運氣。報警管理器不會關閉
有人可以幫我一把。提前致謝。
Intent intent = new Intent(NapAppActivity.this, OnetimeAlarmReceiver.class);
PendingIntent pendingIntent = PendingIntent.getBroadcast(NapAppActivity.this, 1, intent, 0);
Calendar cur_cal = new GregorianCalendar();
cur_cal.setTimeInMillis(System.currentTimeMillis());
Calendar cal = new GregorianCalendar();
cal.add(Calendar.DAY_OF_YEAR, cur_cal.get(Calendar.DAY_OF_YEAR));
cal.set(Calendar.HOUR_OF_DAY, 12);
cal.set(Calendar.MINUTE, 17);
cal.set(Calendar.SECOND, cur_cal.get(Calendar.SECOND));
cal.set(Calendar.MILLISECOND, cur_cal.get(Calendar.MILLISECOND));
cal.set(Calendar.DATE, cur_cal.get(Calendar.DATE));
cal.set(Calendar.MONTH, cur_cal.get(Calendar.MONTH));
AlarmManager alarmManager = (AlarmManager) getSystemService(ALARM_SERVICE);
alarmManager.set(AlarmManager.RTC_WAKEUP, cal.getTimeInMillis(), pendingIntent);
有你的清單 –
是是我做.. –
拜託你'Log.d()'您的預定日期decalred接收機報警和時間? –