我遇到了鬧鐘管理員的問題。我需要將舊鬧鐘設置刪除到特定時間,並將鬧鐘重置爲新時間。我嘗試了很多場景,但都沒有爲我工作。任何幫助應該非常感激。 enter code here
刪除舊的鬧鐘,並設置一個新的鬧鐘管理器
//要刪除報警
am = (AlarmManager) getContext().getSystemService(ALARM_SERVICE);
Intent i = new Intent(getContext(),AlarmReceiver.class);
PendingIntent p = PendingIntent.getBroadcast(getContext(), profileFragmentRequestCode, i, 0);
am.cancel(p);
p.cancel();
//設置新的報警
am = (AlarmManager) getContext().getSystemService(ALARM_SERVICE);
/* Retrieve a PendingIntent that will perform a broadcast */
Intent alarmIntent = new Intent(getContext(), AlarmReceiver.class);
PendingIntent pendingIntent = PendingIntent.getBroadcast(getContext(), profileFragmentRequestCode, alarmIntent, 0);
Calendar calendar = Calendar.getInstance();
calendar.setTimeInMillis(System.currentTimeMillis());
calendar.set(Calendar.HOUR_OF_DAY, 14);
calendar.set(Calendar.MINUTE, 55);
if (android.os.Build.VERSION.SDK_INT >= 19) {
am.setExact(AlarmManager.RTC_WAKEUP, calendar.getTimeInMillis(), pendingIntent);
} else {
am.set(AlarmManager.RTC_WAKEUP, calendar.getTimeInMillis(), pendingIntent);
}
@snachmsm是的,它是一個唯一的號碼,我使用 –