2

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 to JobIntentService
  • moved all logic from onHandleIntent() to onHandleWork()
  • 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?

Glimpse
  • 392
  • 5
  • 20
  • show code where you send broadcast to your receiver – HeyAlex Jun 21 '18 at 14:08
  • Did you get this working? Also, as @HeyAlex said, you are not showing us code how you return data from `JobIntentService`. – c0dehunter Sep 18 '18 at 09:51
  • @PrimožKralj currenlty not on that computer with the source but I did everything as explained in article on link mentioned above as "this article" link. – Glimpse Oct 14 '18 at 21:36

1 Answers1

1

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.

Eric Aya
  • 69,473
  • 35
  • 181
  • 253
Glimpse
  • 392
  • 5
  • 20