我遇到了闹钟管理员的问题。我需要将旧闹钟设置删除到特定时间,并将闹钟重置为新时间。我尝试了很多场景,但都没有为我工作。任何帮助应该非常感激。 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是的,它是一个唯一的号码,我使用 –