午後10時30分に通知を受けました。しかし、私のデバイスが午後10時30分にスイッチオフされ、その後私は11時に私のデバイスをスイッチした後、私はdid notが保留中の通知を取得します。だから私は問題が何であるか理解していない。どんな助けにも感謝します。ブート時にリピートアラームを設定できません
ここで私のコードは作成時のアクティビティです。
Intent alarmIntent = new Intent(CH_Dashboard.this, TimeAlarmEvening.class);
PendingIntent pendingIntent = PendingIntent.getBroadcast(CH_Dashboard.this, 0, alarmIntent, 0);
AlarmManager manager = (AlarmManager) getSystemService(Context.ALARM_SERVICE);
Calendar firingCal = Calendar.getInstance();
Calendar currentCal = Calendar.getInstance();
firingCal.set(Calendar.HOUR, 10);
firingCal.set(Calendar.MINUTE, 30);
firingCal.set(Calendar.SECOND, 0);
firingCal.set(Calendar.AM_PM,Calendar.PM);
long intendedTime = firingCal.getTimeInMillis();
long currentTime = currentCal.getTimeInMillis();
if(intendedTime >= currentTime)
{
manager.setRepeating(AlarmManager.RTC,
intendedTime, AlarmManager.INTERVAL_DAY,
pendingIntent);
}
else
{
firingCal.add(Calendar.DAY_OF_MONTH, 1);
intendedTime = firingCal.getTimeInMillis();
manager.setRepeating(AlarmManager.RTC,
intendedTime, AlarmManager.INTERVAL_DAY,
pendingIntent);
}
私のレシーバコードはここにあり、デバイスがオンのときに正常に通知されます。
Intent notificationIntent = new Intent(context, CH_Dashboard.class);
notificationIntent.putExtra("fromNotification","notify");
TaskStackBuilder stackBuilder = TaskStackBuilder.create(context);
stackBuilder.addParentStack(CH_Dashboard.class);
stackBuilder.addNextIntent(notificationIntent);
PendingIntent pendingIntent = stackBuilder.getPendingIntent(0, PendingIntent.FLAG_UPDATE_CURRENT);
NotificationCompat.Builder builder = new NotificationCompat.Builder(context);
builder.setAutoCancel(true);
Notification notification = builder.setContentTitle("Demo App Notification")
.setContentText("New Notification From Demo App..")
.setTicker("New Message Alert!")
.setSmallIcon(R.mipmap.ic_launcher)
.setContentIntent(pendingIntent).build();
NotificationManager notificationManager = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
notificationManager.notify(0, notification);
ここは私のブートレシーバーコードです。
if (intent.getAction().equals(Intent.ACTION_BOOT_COMPLETED))
{
Intent alarmIntent = new Intent(context, TimeAlarmEvening.class);
PendingIntent pendingIntent = PendingIntent.getBroadcast(context, 0, alarmIntent, 0);
AlarmManager manager = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE);
Calendar firingCal = Calendar.getInstance();
Calendar currentCal = Calendar.getInstance();
firingCal.set(Calendar.HOUR, 10);
firingCal.set(Calendar.MINUTE, 30);
firingCal.set(Calendar.SECOND, 0);
firingCal.set(Calendar.AM_PM,Calendar.PM);
long intendedTime = firingCal.getTimeInMillis();
long currentTime = currentCal.getTimeInMillis();
if(intendedTime >= currentTime)
{
manager.setInexactRepeating(AlarmManager.RTC,
intendedTime, AlarmManager.INTERVAL_DAY,
pendingIntent);
}
else
{
firingCal.add(Calendar.DAY_OF_MONTH, 1);
intendedTime = firingCal.getTimeInMillis();
manager.setInexactRepeating(AlarmManager.RTC,
intendedTime, AlarmManager.INTERVAL_DAY,
pendingIntent);
}
}
最後に、マニフェストでは、受信者を宣言しました。
<receiver
android:name=".model.AutoStart"
android:enabled="true"
android:exported="true">
<intent-filter>
<action android:name="android.intent.action.BOOT_COMPLETED" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</receiver>
<receiver android:name=".TimeAlarmEvening">
<intent-filter>
<action android:name="android.media.action.DISPLAY_NOTIFICATION_EVENING" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</receiver>