Widget issue: BroadcastQueue: Background execution not allowed: receiving Intent

前端 未结 2 1814
不思量自难忘°
不思量自难忘° 2021-01-13 09:07

My app widget stops working after upgrading to targetSDk to 28.

  • It is flawlessly working on old targetsdk devices.

I am getting the following e

2条回答
  •  傲寒
    傲寒 (楼主)
    2021-01-13 09:10

    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);
    }
    

提交回复
热议问题