In my Android app I need to run a background service every time the device is plugged in and idle (it should start after the user connects his device to the charger and end when he disconnects it).
What I want is a similar thing to listening for the ACTION_POWER_CONNECTED broadcast, but targeting Oreo this broadcast doesn't get sent.
I tried Android-Job from Evernote because it doesn't require Google Play Services, as Firebase JobDispatcher does.
new JobRequest.Builder(DemoSyncJob.TAG)
.setRequiresCharging(true)
.setRequiresDeviceIdle(true)
.build()
.schedule();
The problem is that I don't want to have to schedule the job every time. Instead, I want to schedule the job once and have it run every time the user connects his device to the charger.
How can it be done? Thank you.