我的通知安排有问题,我没有收到任何东西,这里是我:
类警报集:
public void AlarmStart() {
Calendar cal = Calendar.getInstance();
cal.setTimeZone(TimeZone.getDefault());
cal.set(Calendar.HOUR_OF_DAY, 20);
cal.set(Calendar.MINUTE, 15);
Intent intent = new Intent(context, AlarmReceiver.class);
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
PendingIntent sender = PendingIntent.getBroadcast(context, 0, intent, PendingIntent.FLAG_CANCEL_CURRENT);
AlarmManager am = (AlarmManager) context.getSystemService(context.ALARM_SERVICE);
am.setRepeating(AlarmManager.RTC_WAKEUP, cal.getTimeInMillis(),AlarmManager.INTERVAL_FIFTEEN_MINUTES, sender);
Log.d("MyActivity", "Set alarmManager.setRepeating to: " + cal.getTime().toLocaleString());
}
类警报接收器:
public void onReceive(Context context, Intent objIntent) {
Log.d("AlarmReceiver", "Called context.startService from AlarmReceiver.onReceive");
}
并在清单中: ... ...
接收器 android:name="AlarmReceiver"> /应用>
我收到第一条日志消息,所以它似乎设置了活动,然后我没有收到任何其他内容。上下文是从另一个活动类传递的,因为它们是简单的类。
知道我错了什么吗?我看过其他用户的代码,它和我的差不多。