Reputation: 402
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:
IntentService
to JobIntentService
onHandleIntent()
to onHandleWork()
android:permission="android.permission.BIND_JOB_SERVICE"
to the service in AndroidManifest file<uses-permission android:name=”android.permission.WAKE_LOCK” />
is already in the use on this projectenqueueWork(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?
Upvotes: 2
Views: 666
Reputation: 402
To make this work, I had to implement everything as described in URLs provided in my question above.
It is really important to be careful when making Intent for sending broadcast.
Instead of
Intent intent = new Intent(action);
Following code should be used:
Intent intent = new Intent(context, clazz);
intent.setAction(action);
Where clazz
is widget provider class.
Upvotes: 1