java - 自定义意图广播
问题描述
Android 8.0 (Oreo) 引入了新的电池使用优化,包括隐式广播。我们有主应用程序和额外安装的插件 (apks)。主应用程序发送带有动作“POLL_PLUGINS”的自定义广播,以确定已安装哪些并与它们共享授权数据。问题是在 android 8.0 上的插件中无法接收广播。这是发送广播的代码:
Intent intent=new Intent();
intent.setAction("<PACKAGE_NAME>.POLL_PLUGINS");
intent.putExtra ("auth", "<ENCRYPTED_DATA>"));
intent.addFlags(Intent.FLAG_INCLUDE_STOPPED_PACKAGES);
context.sendBroadcast(intent);
和插件的主要接收器:
<receiver
android:name=".PluginReceiver"
android:enabled="true"
android:exported="true">
<intent-filter android:priority="100000000">
<action android:name="<PACKAGE_NAME>.POLL_PLUGINS"/>
<action android:name="<PACKAGE_NAME>.plugin1.START"/>
</intent-filter>
</receiver>
和插件的接收器:
public class PluginReceiver extends BroadcastReceiver
{
@Override
public void onReceive(Context context, Intent intent)
{
Log.d ("Plugin/Receiver","Plugin1 received data"); //<-- not being executed at all
MainConn.parseBroadCastIntent (context,intent,R.mipmap.ico_crm, MainActivity.class);
}
}
在以前的机器人上工作得很好。我如何使用相同的方案或是否有其他解决方法?
解决方案
注意:如果您的应用以 API 级别 26 或更高级别为目标,则您不能使用清单为隐式广播(不专门针对您的应用的广播)声明接收器,但一些不受该限制的隐式广播除外。在大多数情况下,您可以改用计划作业。
更多详情见详情
推荐阅读
- amazon-web-services - AWS 云形成 - 使用安全组名称创建 EC2 实例
- angular - Angular6:如何将模板变量链接到服务的数组,索引在 paramMap
- python - 使用 for 和 while 循环编写素数函数的最 Pythonic 方式是什么?
- ruby-on-rails - 在 Ruby 中的表单内调用另一个控制器
- c# - 所需功能已贬值,如何使其 appium 与 Android 驱动程序一起使用?
- angular - NgbDropdown 下拉按钮的自定义箭头
- c# - 如何在 C# 中将 char 与字符串一起使用?
- python - X-13-ARIMA 与 statsmodels.tsa.x13
- code-analysis - 如何持久化 NDepend 项目的分析结果?
- python - python包装列表并在美丽的汤中转换类型