Android闹钟和广播

时间:2014-04-09 06:14:21

标签: android android-broadcast

我已经定义了我的Android闹钟和BroadcastReceiver,如下所示。我的希望是我希望警报在两分钟之后以及随后的每15分钟发出一次。这似乎没有发生。这是为什么?

Calendar calendar = Calendar.getInstance();
calendar.set(Calendar.MINUTE, calendar.get(Calendar.MINUTE) + 2);
PendingIntent pi = PendingIntent.getBroadcast(getApplicationContext(), 0, new Intent(getApplicationContext(), DailyNotificationReceiver.class), PendingIntent.FLAG_UPDATE_CURRENT);
AlarmManager am = (AlarmManager) getApplicationContext().getSystemService(Context.ALARM_SERVICE);
am.setRepeating(AlarmManager.RTC_WAKEUP, calendar.getTimeInMillis(), AlarmManager.INTERVAL_FIFTEEN_MINUTES, pi);


public class DailyNotificationReceiver extends BroadcastReceiver {

    @Override
    public void onReceive(Context context, Intent intent) {
        Log.d("received", "received");
        }
}

1 个答案:

答案 0 :(得分:1)

正如评论中所讨论的,BroadcastReceiver未注册。

请在BroadcastReceiver

中注册manifest