
Detect User Inactivity System-Wide on Android with AccessibilityService
Here is a scenario you will run into sooner or later building Android kiosk apps, digital signage, or any long-running background service: you need to know when the user has not interacted with the device for a certain amount of time. Maybe you want to show content after 20 seconds of idle time, then dismiss it the instant someone touches the screen again. You start looking for the right API. PowerManager.isInteractive() tells you if the screen is on, not if anyone is actually using it. onUserInteraction() in an Activity only fires when your own Activity is in the foreground. There is no getLastInteractionTime() anywhere in the SDK. Eventually you land on AccessibilityService , try it, and it works perfectly. This article walks you through exactly how, and why. What is AccessibilityService really doing here AccessibilityService is designed for assistive technology — screen readers, switch access, voice control. That is its primary documented purpose. But what makes it useful for our us
Continue reading on Dev.to
Opens in a new tab



