How to add screenshot feature in accessibility service in android studio

117 views Asked by At

Issue Description

I'm developing an Android accessibility service in Kotlin for periodic screen capture. However, I'm facing issues with the rootNode being null, impacting the reliability of screen capture.

Code Snippet

class ScreenshotService : AccessibilityService() {

    private lateinit var rootNode: AccessibilityNodeInfo

    override fun onAccessibilityEvent(event: AccessibilityEvent?) {
        rootNode = rootInActiveWindow
        // Other logic for handling accessibility events...
        captureScreen()
    }

    private fun captureScreen() {
        try {
            // Attempt to capture the screen using rootNode
            // ...
        } catch (e: Exception) {
            e.printStackTrace()
        }
    }

    override fun onInterrupt() {
        // Handle interruptions (if needed)
    }
}


i tried the above code but i m getiing null any kind of help would be useful.
0

There are 0 answers