Search code examples
androidaccessibilityservice

Accessibility setting change value on Shared Preferences


I have an App which have behavior like a KIOS. There is an Activity will show to user and user cannot back or close it because it's need a password.

There is one case if the owner of App forgot the password. So I need to implement external setting (like IOS) outside the App to change value on my Shared Preferences to close the Activity KIOS.

I read some articles and the close way is using Accessibility but the information and example about this is so difficult to find. So I still learn and testing about it.

Here what I've done:

SettingProgram.java

public class SettingProgram extends AccessibilityService {
    public static boolean isGuestMode = false;

    @Override
    public void onAccessibilityEvent(AccessibilityEvent event) {
//            isGuestMode = false;


    /*I want to 
      if switch the Accessibility turn on the boolean isGuestMode become true, 
      and if it turn off the isGuestMode become false
     */
    }

    @Override
    public void onInterrupt() { }

    @Override
    protected void onServiceConnected() {
        super.onServiceConnected();
    }
}

accessibility_services.xml

<?xml version="1.0" encoding="utf-8"?>
<accessibility-service 
xmlns:android="http://schemas.android.com/apk/res/android"
    android:description="@string/accessibility_service_description"
    android:accessibilityEventTypes="typeAllMask"
    android:accessibilityFlags="flagReportViewIds"
    android:canRetrieveWindowContent="true"
    android:canRequestTouchExplorationMode="true"
    android:accessibilityFeedbackType="feedbackSpoken"
    android:notificationTimeout="100" 
    android:settingsActivity="com.mobile.Testing.SettingProgram"/>

I have read:

https://codelabs.developers.google.com/codelabs/developing-android-a11y-service/index.html?index=..%2F..%2Findex#0

https://developer.android.com/guide/topics/ui/accessibility/services


Solution

  • I've done this with Accessibility Service to call another layout. Here the way :

    • I create accessibility xml file as documentation say like below :

    <accessibility-service
       xmlns:android="http://schemas.android.com/apk/res/android"
       android:description="@string/accessibility_service_description"
       android:accessibilityFeedbackType="feedbackGeneric"
       android:accessibilityFlags="flagDefault"
       android:canRetrieveWindowContent="true"
       android:settingsActivity="com.mobile.vhp.checkin.SettingAndList.GeneralSetting"/>   
    

    From that, I have Accessibility Service for my App in Setting which have and Option Menu name Guest Mode. The guest mode will call General Setting Activity to set another setting for my Apps outside the App.