我有一个为 jelly bean 开发的应用程序,我在其中使用警报管理器安排了一个要在将来执行的事件。只要应用程序在前台或后台运行,预定事件就会按预期执行。但是一旦我强行关闭了taskmanager下的应用,我就再也收不到alarm manager的广播了。
根据各种帖子和博客的建议,我尝试使用 Intent.Flag_Include_Stopped_Packages。但这没有用。在 Intent 中包含此标志仅适用于 sendBroadcast(intent)。但是在使用挂起 Intent 的警报管理器的情况下,它不起作用。
我的代码来安排闹钟
Intent intent = new Intent("com.dummy.intent");
intent.addFlags(Intent.FLAG_INCLUDE_STOPPED_PACKAGES);
PendingIntent pi = PendingIntent.getBroadcast(getApplicationContext(),dummyId, intent, PendingIntent.FLAG_CANCEL_CURRENT);
AlarmManager alarm = (AlarmManager)getSystemService(ALARM_SERVICE);
alarm.set(AlarmManager.RTC_WAKEUP, scheduledAlarm.getTimeInMillis(), pi);
我的主菜
<receiver android:name="com.example.androidScheduling.alarmReceiver"
android:enabled="true"
android:exported="true"
android:process=":remote">
<intent-filter>
<action android:name="com.dummy.intent"></action>
</intent-filter>
</receiver>
有人可以帮帮我吗?
我什至尝试在 list 中为接收器包含 android:process = ":remote"
。但即使那样也无济于事。
最佳答案
我认为您没有正确拼写 Intent 在 list 和程序中的操作名称。
程序语法
Intent intent = new Intent("com.dummy.intent");
list 文件
-
<intent-filter>
<action android:name="com.custom.intent"></action>
</intent-filter>
Intent 和 list 中声明的操作名称必须相同
。
希望对你有帮助
关于android - 应用程序强制关闭时未执行广播接收器,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17994167/