本文介绍了窗口小部件问题:BroadcastQueue:不允许后台执行:接收Intent的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我的应用程序小部件在升级到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 文件内容在下面给出-
androidmanifest.xml file contents are given below-
<!-- 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>
还有我的尊敬的班级代码(
And my reviever class code(
@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);
}
项目链接以供参考.关注了以前的帖子,但是没有用.
project link for reference. Followed previous posts but did not worked.
推荐答案
问题出在您在 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:不允许后台执行:接收Intent的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!