gpt4 book ai didi

android - 小部件问题 : BroadcastQueue: Background execution not allowed: receiving Intent

转载 作者:塔克拉玛干 更新时间:2023-11-02 22:50:52 26 4
gpt4 key购买 nike

我的应用小部件在升级到 targetSDK 到 28 后停止工作。

  • 它在旧的 targetsdk 设备上完美运行。

我收到以下错误:

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>

还有我的reviever类代码(

 @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 的地方。

世界时钟 Activity

  private static void sendWidgetRefresh(Context context) {
// send update broadcast to widget
Intent broadcast = new Intent(ClockWidgetProvider.WIDGET_DATA_CHANGED_ACTION);
context.sendBroadcast(broadcast);
}

项目 link以供引用。按照以前的帖子,但没有奏效。

Oreo - Widget services and broadcast receiver: Not allowed to start service Intent

最佳答案

问题出在您在 sendWidgetRefresh 中进行的隐式广播中。你可以通过在你的 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);
}

关于android - 小部件问题 : BroadcastQueue: Background execution not allowed: receiving Intent,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53578252/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com