skip to Main Content

I have created android tv app by using custom accessibility service. I am using it to listen "HOME" button key event to launch my app (when user presses "HOME" button on d-pad). Everything works fine but sometimes I observed, the accessibility service get disabled automatically.

When I checked to Settings > Accessibility > My_APP, I found the below case.

  1. My_APP > showing accessibility as "OFF"
  2. When I clicked and moved to "enable" the service, it was showing "Enabled" flag as ON(means, it was enabled as shown in images)
  1. showing "Off" in app name
  2. showing "Enabled" when goto enable

What is the reason behind this? What I am doing wrong here or How I need to handle this, where accessibility should not disabled automatically until user disables it?

Below is my service_config.xml

<accessibility-service xmlns:android="http://schemas.android.com/apk/res/android"
    android:accessibilityEventTypes="typeViewClicked"
    android:accessibilityFeedbackType="feedbackGeneric|feedbackVisual"
    android:canRetrieveWindowContent="true"
    android:accessibilityFlags="flagReportViewIds|flagRequestFilterKeyEvents"
    android:description="@string/app_name"
    android:canPerformGestures="true"
    android:canRequestFilterKeyEvents ="true"
    android:notificationTimeout="150"/>

My app has sdk support as below:
minSdk = 26, targetSdk = 34
and AGP version = 8.3.2

I have tried this on google chrome cast with android 12.

3

Answers


  1. It happens on my tv tv security app make this, disable it with adb or give permission in security app too it work on my tcl google tv

    Login or Signup to reply.
  2. Your accessibility service is being automatically disabled because Android restricts apps from intercepting protected key events like the “HOME” button for security reasons. When your app tries to listen for the “HOME” button press, the system may detect this and disable your service to prevent misuse. To resolve this, avoid intercepting the “HOME” button and redesign your app to function without relying on capturing this key event.

    Login or Signup to reply.
  3. Try to change:

    android:accessibilityFlags="flagReportViewIds|flagRequestFilterKeyEvents"
    

    To

    android:accessibilityFlags="flagRequestFilterKeyEvents"
    

    So the accessibility service will be explicitly enabled by the user.

    Also add in androidmanifest.xml

    <application
        android:accessibilityFlags="flagRequestFilterKeyEvents"
    

    To ensure that the accessibility service is not disabled automatically

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search