我已设置闹钟并且工作正常,但每次重新启动手机时闹钟都会启动。
我希望当手机重新启动闹钟仍然有效时,如果闹钟应该在手机关闭时启动,则手机开机后将开始闹铃。
Intent alarmIntent = new Intent(Form.this, AlarmReceiver.class);
PendingIntent pIntent = PendingIntent.getBroadcast(Form.this, 0, alarmIntent, 0);
AlarmManager manager = (AlarmManager) getSystemService(Context.ALARM_SERVICE);
/* Set the alarm to start at 00:00 AM */
Calendar Time = Calendar.getInstance();
Time.set(Calendar.SECOND, 0);
Time.set(Calendar.MINUTE, Minute);
Time.set(Calendar.HOUR_OF_DAY, Hour);
/* Repeating on every day minutes interval */
manager.setRepeating(AlarmManager.RTC, Time.getTimeInMillis(),
AlarmManager.INTERVAL_DAY, pIntent);
Intent alarmIntent = new Intent(Form.this, AlarmReceiver.class);
PendingIntent pIntent = PendingIntent.getBroadcast(Form.this, 0, alarmIntent, 0);
AlarmManager manager = (AlarmManager) getSystemService(Context.ALARM_SERVICE);
/* Set the alarm to start at 00:00 AM */
Calendar Time = Calendar.getInstance();
Time.set(Calendar.SECOND, 0);
Time.set(Calendar.MINUTE, Minute);
Time.set(Calendar.HOUR_OF_DAY, Hour);
/* Repeating on every day minutes interval */
manager.setRepeating(AlarmManager.RTC, Time.getTimeInMillis(),
AlarmManager.INTERVAL_DAY, pIntent);
表现
<receiver
android:name=".AlarmReceiver"
android:enabled="true"
android:exported="true" >
<action android:name="android.intent.action.BOOT_COMPLETED" />
</intent-filter>
任何想法?
答案 0 :(得分:0)
希望变量Minute
和Hour
中的值指的是当前时间的未来时间,否则如果警报的值为&lt; =当前时间,警报将立即触发。