我有一个闹钟,我想每天重复
。 Intent intent=new Intent(this, AlarmService.class);
AlarmManager alarmManager = (AlarmManager)getSystemService(ALARM_SERVICE);
PendingIntent pendingIntent=PendingIntent.getBroadcast(this, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT);
// PendingIntent.getBroadcast(this, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT);
Calendar calendar = Calendar.getInstance();
calendar.set(Calendar.HOUR_OF_DAY, hour); // For 1 PM or 2 PM
calendar.set(Calendar.MINUTE, minute);
calendar.set(Calendar.SECOND, 0);
long cuurent=calendar.getTimeInMillis();
alarmManager.setRepeating(AlarmManager.RTC_WAKEUP, calendar.getTimeInMillis(),
AlarmManager.INTERVAL_DAY, pendingIntent);
但不调用广播接收器。
您的PendingIntent
正在调用getBroadcast
,但看起来您的意图是服务。 如果这是真的,请将您的 PendingIntent 更改为像这样调用getService
:
PendingIntent pendingIntent=PendingIntent.getService(this, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT);