我在设备启动时设置了2个不同的每周重复通知警报,并带有以下代码
public class MyRebootReceiver extends BroadcastReceiver {
@Override
public void onReceive(Context context, Intent intent) {
if ("android.intent.action.BOOT_COMPLETED".equals(intent.getAction())) {
Calendar calendar = Calendar.getInstance();
calendar.setTimeZone(TimeZone.getTimeZone("UTC"));
calendar.setTimeInMillis(firstMonday(calendar.getTimeInMillis() / 1000) * 1000);
setAlarm(context,calendar,5);
calendar = Calendar.getInstance();
calendar.setTimeZone(TimeZone.getTimeZone("UTC"));
calendar.setTimeInMillis(firstSutuday(calendar.getTimeInMillis() / 1000) * 1000);
setAlarm(context,calendar,7);
}
}
protected void setAlarm(Context context, Calendar setalarmon, int id ) {
Intent i = new Intent(context, AlarmClass.class);
i.putExtra("KEY", id);
PendingIntent pi = PendingIntent.getService(context, id, i, PendingIntent.FLAG_UPDATE_CURRENT);
AlarmManager am = (AlarmManager) context.getSystemService(context.ALARM_SERVICE);
am.setRepeating(AlarmManager.RTC_WAKEUP, setalarmon.getTimeInMillis(), 1000 * 60 * 60 * 24 * 7, pi);
}
接收类是AlarmClass,它是
public class AlarmClass extends BroadcastReceiver{
@TargetApi(Build.VERSION_CODES.HONEYCOMB)
@Override
public void onReceive(Context context, Intent arg1){
int key = arg1.getIntExtra("KEY",-1);
NotificationManager notificationManager
= (NotificationManager)context.getSystemService(Context.NOTIFICATION_SERVICE);
Notification.Builder builder = new Notification.Builder(context);
Intent intent = new Intent(context, MainActivity.class);
PendingIntent pendingIntent = PendingIntent.getActivity(context, 0, intent, 0);
Uri uri= RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);
long[] v = {500,1000};
builder
.setSmallIcon(R.drawable.ic_launcher)
.setContentTitle("Test")
.setContentText("This is a test ")
.setContentInfo(" ")
.setTicker(" Test ");
.setSound(uri)
.setVibrate(v)
.setDefaults(Notification.DEFAULT_LIGHTS)
.setContentIntent(pendingIntent)
.setAutoCancel(true);
Notification notification = builder.build();
notificationManager.notify(key, notification);
}
}
所以我期待每个星期六23:00和每个星期一当地时间11:00发出一次警报但是我没有得到Suturday警报的任何通知,尽管我在手机中看到的时候我使用了adb shell dumpsys警报命令,警报通知在正确的时间退出,Sutudays警报设置为下周
知道为什么我没有收到警报吗?