Проблема с виджетом: BroadcastQueue: Фоновое выполнение не разрешено: получение намерения - PullRequest
0 голосов
/ 02 декабря 2018

Виджет моего приложения перестает работать после обновления до targetSDk до 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>

И мой код класса 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.

активность мирового времени

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

проект ссылка для справки. Следил за предыдущими постами, но не работал.

Oreo - службы виджетов и приемник вещания: запуск службы запрещен. Намерение

1 Ответ

0 голосов
/ 24 декабря 2018

Проблема в неявной трансляции, которую вы выполняете в sendWidgetRefresh .Вы можете преодолеть запрет, указав имя компонента в своем намерении.

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