Service not starting on Oreo in app widget using PendingIntent

前端 未结 3 529
栀梦
栀梦 2020-12-31 02:37

I\'m using Android app widgets. I\'m creating a PendingIntent object and use it in the method RemoteViews#setOnClickPendingIntent(). This is the pe

3条回答
  •  难免孤独
    2020-12-31 02:49

    As you note, an app widget does not count for the PendingIntent background whitelist. I do not know why — it would seem to be about on par with a PendingIntent started by a Notification. Perhaps it's an issue that the Notification is a system thing, whereas the app widget is a home screen thing. Regardless, you could:

    • Use getForegroundService(), as you have, or

    • Try getBroadcast() with an explicit Intent, and with the BroadcastReceiver starting a JobIntentService, if you do not want to raise a Notification (as a foreground service requires)

    Based on your symptoms, you appear to have tripped over what I would consider to be a bug: there should be a way to switch from getService() to getForegroundService() without having to reboot. :-) I'll try to run some experiments and will file an issue if I can reproduce the problem.

提交回复
热议问题