安卓重复每日警报无法正确重复



我有一个闹钟,我想每天重复

    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);

相关内容

  • 没有找到相关文章

最新更新