0
您是否知道无法通过“Hi everyone”开始提问?即时触发本地通知
大家好,
通知立即在第一次启动时出现。以下是设置通知的代码。它应该每天9点到10点出现。
Calendar calendar = Calendar.getInstance();
calendar.set(Calendar.HOUR_OF_DAY, hour);
calendar.set(Calendar.MINUTE, minute);
calendar.set(Calendar.SECOND, 0);
Log.v("TIMETIME", "schedule reminder: " + hour + ":" + minute);
Intent notificationIntent = new Intent(context, AlarmReceiver.class);
notificationIntent.putExtra(AlarmReceiver.NOTIFICATION_ID, 1);
notificationIntent.putExtra(AlarmReceiver.NOTIFICATION, getNotification(context));
PendingIntent pendingIntent = PendingIntent.getBroadcast(context, 0, notificationIntent, PendingIntent.FLAG_UPDATE_CURRENT);
AlarmManager alarmManager = (AlarmManager)context.getSystemService(Context.ALARM_SERVICE);
alarmManager.setRepeating(AlarmManager.RTC_WAKEUP, calendar.getTimeInMillis(), AlarmManager.INTERVAL_DAY, pendingIntent);
在另一方面是报警广播接收器
NotificationManager notificationManager = (NotificationManager)context.getSystemService(Context.NOTIFICATION_SERVICE);
Notification notification = intent.getParcelableExtra(NOTIFICATION);
int id = intent.getIntExtra(NOTIFICATION_ID, 0);
notificationManager.notify(id, notification);
死的简单,但不工作。