I'm developing a Flutter app and aiming to create a functionality that specifically identifies ** when a user is watching YouTube Shorts within the official YouTube app.** Currently, I've successfully implemented a termination mechanism for the entire YouTube app after 5 seconds, but I need a solution that triggers only when the user is watching YouTube Shorts.

I have used the following using kotlin: AccessibilityEvent FlutterActivity AccessibilityService override fun onAccessibilityEvent(event: AccessibilityEvent?) {

    val eventType = event?.eventType ?: return
     
    when (eventType) {
        AccessibilityEvent.TYPE_WINDOW_STATE_CHANGED -> {
            // Check if the window state has changed
            val newPackageName = event.packageName?.toString() ?: return
            println("Content Description: $event")
            if (newPackageName != currentPackageName) {
       
                saveScreenTime()
                currentPackageName = newPackageName
                if(newPackageName == "com.google.android.youtube"){
                // If the window has changed, save the current screen time and start a new timer
     
                // Update the current package name
                currentPackageName = newPackageName
                // Start a new timer for the current window
                startScreenTimeTimer()
                }
            }
        }
    }
    
}
0

There are 0 best solutions below