I\'m building an Android application, which makes use of a manifest broadcast receiver to know when the device is plugged in. I think Android 5.0 JobScheduler API would be a mu
I think Android 5.0 JobScheduler API would be a much better way of doing this
Well, that depends on what "this" is. Simply knowing when the device is plugged in is pointless unless you are going to do something with that information, and we do not know what you have in mind.
Bear in mind that JobScheduler
does not necessarily give you control when the device is plugged in. Rather, it uses that fact, plus your JobInfo
and other environmental factors, to determine when to give you control.
is it possible to use this API or a similar one on earlier versions of Android?
There is no backport of JobScheduler
supplied by the Android SDK at this time. While somebody will likely write a backport at some point, I am not aware of one available as open source at the moment either.
If it is not possible, what would be the best option to do this (instead of a manifest broadcast receiver)?
Again, it depends on what "this" really is. For example, if you are trying to say "I want to get control every so often, but only if the device is plugged in", you could use AlarmManager
, then check to see whether the device is plugged in before continuing with your work.