android intercept recent apps button

前端 未结 5 920
暖寄归人
暖寄归人 2020-12-01 07:09

I have an application meant for children and I do not want them to be able to click the \"Recent Apps\" button (the one that looks like two rectangles on top of each other).

5条回答
  •  被撕碎了的回忆
    2020-12-01 07:41

    In the accepted answer you're using ClassName only for Android 4.2 - 4.4. It won't work on 5.0 and higher, or Android 4.1.

    Here is the list of ClassNames for main Android versions:

    • Android 4.1: "com.android.internal.policy.impl.RecentApplicationsDialog"
    • Android 4.2 - 4.4: "com.android.systemui.recent.RecentsActivity"
    • Android 5.0 - 7.1: "com.android.systemui.recents.RecentsActivity" ("s" letter was added)

    The best solution for you will be to utilize Accessibility Service. Override onAccessibilityEvent() method, filter out ClassNames listed above and do something when you detect this event. For example simulate pressing the 'Home' button. You can do this by making a global action in Accessibility Service.

提交回复
热议问题