小部件问题:BroadcastQueue:不允许后台执行:接收意图 [英] Widget issue: BroadcastQueue: Background execution not allowed: receiving Intent
本文介绍了小部件问题:BroadcastQueue:不允许后台执行:接收意图的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
升级到 targetSDk 到 28 后,我的应用小部件停止工作.
My app widget stops working after upgrading to targetSDk to 28.
- 它可以在旧的 targetdk 设备上完美运行.
我收到以下错误:
W/BroadcastQueue: Background execution not allowed: receiving Intent { act=ch.corten.aha.worldclock.WIDGET_DATA_CHANGED flg=0x10 } to ch.corten.aha.worldclock/.WorldClockWidgetProvider
W/BroadcastQueue: Background execution not allowed: receiving Intent { act=ch.corten.aha.worldclock.WIDGET_DATA_CHANGED flg=0x10 } to ch.corten.aha.worldclock/.WeatherWidgetProvider
androidmanifest.xml 文件内容如下-
<!-- clock widget -->
<receiver
android:name=".WorldClockWidgetProvider"
android:exported="false"
android:label="@string/clock_widget_name" >
<intent-filter>
<action android:name="android.appwidget.action.APPWIDGET_UPDATE" />
</intent-filter>
<intent-filter>
<action android:name="android.appwidget.action.APPWIDGET_DISABLED" />
</intent-filter>
<intent-filter>
<action android:name="android.appwidget.action.APPWIDGET_ENABLED" />
</intent-filter>
<intent-filter>
<action android:name="ch.corten.aha.worldclock.WIDGET_DATA_CHANGED" />
</intent-filter>
<intent-filter>
<action android:name="ch.corten.aha.worldclock.CLOCK_TICK" />
</intent-filter>
<meta-data
android:name="android.appwidget.provider"
android:resource="@xml/world_clock_appwidget_info" />
</receiver>
<receiver
android:name=".WeatherWidgetProvider"
android:enabled="@bool/enable_weather_widget"
android:exported="false"
android:label="@string/weather_widget_name" >
<intent-filter>
<action android:name="android.appwidget.action.APPWIDGET_UPDATE" />
</intent-filter>
<intent-filter>
<action android:name="android.appwidget.action.APPWIDGET_DISABLED" />
</intent-filter>
<intent-filter>
<action android:name="android.appwidget.action.APPWIDGET_ENABLED" />
</intent-filter>
<intent-filter>
<action android:name="ch.corten.aha.worldclock.WIDGET_DATA_CHANGED" />
</intent-filter>
<intent-filter>
<action android:name="ch.corten.aha.worldclock.CLOCK_TICK" />
</intent-filter>
<meta-data
android:name="android.appwidget.provider"
android:resource="@xml/weather_appwidget_info" />
</receiver>
还有我的复习课代码(
@Override
public void onReceive(Context context, Intent intent) {
super.onReceive(context, intent);
if (WIDGET_DATA_CHANGED_ACTION.equals(intent.getAction())
|| CLOCK_TICK_ACTION.equals(intent.getAction())) {
PowerManager pm = (PowerManager) context.getSystemService(Context.POWER_SERVICE);
if (pm.isScreenOn()) {
onClockTick(context);
}
}
}
时钟小部件提供程序扩展 AppWidgetProvider 的地方.
Where clock widget provider is extending AppWidgetProvider.
世界时钟活动
private static void sendWidgetRefresh(Context context) {
// send update broadcast to widget
Intent broadcast = new Intent(ClockWidgetProvider.WIDGET_DATA_CHANGED_ACTION);
context.sendBroadcast(broadcast);
}
项目 link 供参考.按照以前的帖子,但没有奏效.
project link for reference. Followed previous posts but did not worked.
Oreo - 小工具服务和广播接收器:不允许启动服务 Intent
推荐答案
问题在于您在 sendWidgetRefresh 中进行的隐式广播.你可以通过在你的意图中定义一个组件名称来突破禁令.
The problem is in implicit broadcast that you're making in sendWidgetRefresh. You can break through the ban by defining a component name in your intent.
private static void sendWidgetRefresh(Context context) {
// send update broadcast to widget
Intent broadcast = new Intent(ClockWidgetProvider.WIDGET_DATA_CHANGED_ACTION);
ComponentName componentName = new ComponentName(context, WorldClockWidgetProvider.class);
broadcast.setComponent(componentName);
context.sendBroadcast(broadcast);
}
这篇关于小部件问题:BroadcastQueue:不允许后台执行:接收意图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文