Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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

  • It is flawlessly working on old targetsdk devices.

I am getting the following error:

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

Where clock widget provider is extending AppWidgetProvider.

world clock activity

  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.

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

like image 874
Biswajit Das Avatar asked Dec 02 '18 07:12

Biswajit Das


1 Answers

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);
}
like image 93
HeyAlex Avatar answered Sep 17 '22 16:09

HeyAlex