student93
student93

Reputation: 307

Set job scheduler when screen is on (device NOT idle)?

I know that the method setRequiresDeviceIdle(boolean requiresDeviceIdle) makes the job run when the device to be in idle mode.

What I want is the opposite, I want the job to run when the device isn't in idle mode (screen is on and the user is using the phone) and I know that setRequiresDeviceIdle(false) doesn't do the job because saying "false" means that it isn't required so it'll run when it is idle and when it isn't.

Upvotes: 4

Views: 1767

Answers (1)

ianhanniballake
ianhanniballake

Reputation: 199920

This is not possible via JobScheduler. If you wish trigger behavior based on the screen turning on, you must constantly be running (most likely as a foreground service) and programmatically register a BroadcastReceiver listening for ACTION_SCREEN_ON.

Obviously this is memory intensive and a horrible idea for overall system health which is why it is not supported by JobScheduler (not mentioning the significant memory pressure already present during ACTION_SCREEN_ON due to it being one of the conditions of coming out of Android 7.0's light doze).

Upvotes: 2

Related Questions