android - 应用程序强制关闭时未执行广播接收器

标签 android android-intent broadcastreceiver alarmmanager

我有一个为 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/

相关文章:

java - Android 类型 new View.OnClickListener(){} 未定义方法 startActivity(Intent)

android - Android TV 中以太网 (RJ45) 和 USB 的广播接收器

android - 警报管理器未激活广播接收器?

Android facebook 4.0.0 分享对话框不分享内容

java - 在 Android 中将错误登录尝试按钮延迟 10 秒然后再次启用?

android - 从 2 个不同的父 Activity 调用子 Activity 时如何处理向上按钮操作

android - onReceive 方法没有被调用

android - 以编程方式绘制多个矩形

Android Volley Post 请求 - JsonArrayRequest 的解决方法

android - Activity 返回图像