重启一次后通知运行 [英] Notification run after reboot once
问题描述
我想在重启后通知工作。我提醒开始但是一次。如果我然后改变手机上的日期 - 那么没有通知。只有再次运行应用程序,它们才会。也就是说,重新启动手机而不启动应用程序通知只会出现一次 - 当您启动手机时。
I want to notification worked after a reboot. I reminder starts but once. If I then change the date on the phone ahead - then no notifications. Only if you run the application again, then they will. That is, after you restart the phone without launching the application notifications appear only once - when you start your phone.
我在 MainActivity中设置了通知时间:
Intent myIntent = new Intent(MainActivity.this, MyReceiver.class);
pendingIntent = PendingIntent.getBroadcast(MainActivity.this, 0, myIntent,0);
AlarmManager alarmManager = (AlarmManager)getSystemService(ALARM_SERVICE);
alarmManager.setRepeating(AlarmManager.RTC, c1.getTimeInMillis(), AlarmManager.INTERVAL_DAY, pendingIntent);
MyAlarmService (onCreate):
MyAlarmService(onCreate):
mManager =(NotificationManager)this.getApplicationContext().getSystemService(this.getApplicationContext().NOTIFICATION_SERVICE);
Intent intent1 = new Intent(this.getApplicationContext(),MainActivity.class);
Notification notification = new Notification(R.drawable.ic_launcher,"Title", System.currentTimeMillis());
intent1.addFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP| Intent.FLAG_ACTIVITY_CLEAR_TOP);
PendingIntent pendingNotificationIntent = PendingIntent.getActivity(this.getApplicationContext(), 0, intent1, PendingIntent.FLAG_UPDATE_CURRENT);
notification.flags |= Notification.FLAG_AUTO_CANCEL;
notification.setLatestEventInfo(this.getApplicationContext(), "Title", "Description", pendingNotificationIntent);
mManager.notify(0, notification);
MyReceiver:
Intent service1 = new Intent(context, MyAlarmService.class);
context.startService(service1);
AndroidManifest(MyReceiver and Service):
<service android:name=".MyAlarmService"
android:enabled="true"/>
<receiver android:name=".MyReceiver"
android:enabled="true"
android:exported="false"
android:label="MyReceiver">
<intent-filter >
<action android:name="android.intent.action.BOOT_COMPLETED"/>
<action android:name="android.intent.action.QUICKBOOT_POWERON"/>
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</receiver>
推荐答案
重启后通知(AlarmManager)丢失。看来你需要在重启时重置Alarmanager setRepeating()
Notification (AlarmManager) are lost after reboot. It seems you need to reset Alarmanager setRepeating() on reboot
请检查这个帖子:
这篇关于重启一次后通知运行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!