我有这段代码,但闹钟不会从一开始就开始。我希望myReceiver
从分钟开始开始,并且从一开始就重复它。我怎样才能做到这一点?
PendingIntent pendingIntent3;
AlarmManager manager =(AlarmManager) getSystemService(Context.ALARM_SERVICE);
Intent alarmIntent3 = new Intent(getBaseContext(), myReceiver.class);
pendingIntent3 = PendingIntent.getBroadcast(getBaseContext(), 0, alarmIntent3, 0);
manager.setRepeating(AlarmManager.ELAPSED_REALTIME _WAKEUP,
SystemClock.currentThreadTimeMillis(),
1*60*1000, pendingIntent3);
答案 0 :(得分:1)
使用以下代码设置重复闹铃:
Intent alarmIntent3 = new Intent(getBaseContext(), myReceiver.class);
PendingIntent pendingIntent3 = PendingIntent.getBroadcast(getBaseContext(), 0, alarmIntent3, PendingIntent.FLAG_UPDATE_CURRENT);
// Current time
Calendar calendarNotifiedTime = Calendar.getInstance();
calendarNotifiedTime.setTimeInMillis(System.currentTimeMillis());
calendarNotifiedTime.set(Calendar.SECOND, 0);
// Set alarm
AlarmManager manager =(AlarmManager) getSystemService(Context.ALARM_SERVICE);
manager.setRepeating(AlarmManager.RTC_WAKEUP, calendarNotifiedTime.getTimeInMillis(), 1*60*1000, pendingIntent3);
确保您已在myReceiver
中声明AndroidManifest.xml
BroadcastReceiver。