My app contains home widgets which are updated periodically using IntentService
.
Now, when targeting API level 26 I had to change this a little bit because of restrictions on Oreo. You can find more info here.
I found this article in which it is described how to make IntentService work on Oreo.
I did everything as described:
- Converted my
IntentService
toJobIntentService
- moved all logic from
onHandleIntent()
toonHandleWork()
- Added
android:permission="android.permission.BIND_JOB_SERVICE"
to the service in AndroidManifest file - also,
<uses-permission android:name=”android.permission.WAKE_LOCK” />
is already in the use on this project - I went further and started using following logic for starting the Service:
enqueueWork(context, LocationForecastService.class, JOB_ID, work);
It still doesn't refresh or initialize widget properly. Service actually starts, downloads data but problem might be somewhere with sending data via broadcast. It works when API level is set to 24.
Widgets are registered as BroadcastReceivers in the AndroidManifest file like this:
<receiver
android:name=".widgets.provider.WeekWidgetProvider"
android:label="@string/Widget_WeekForecast_Title">
<intent-filter>
<action android:name="android.appwidget.action.APPWIDGET_UPDATE" />
<action android:name="action_widget_data_change_event" />
<action android:name="action_week_widget_data_change_event" />
</intent-filter>
<meta-data
android:name="android.appwidget.provider"
android:resource="@xml/appwidget_week_provider_layout" />
</receiver>
Anyone got into the similar problem?