Search code examples
androidkotlinaccessibilitytalkback

Android Talkback accessibility events


Is there a way to programatically set to read all views on talkback when certain action is fired (ex. button click) like it is when you tap with 3 fingers at once?

Thanks in advance.


Solution

  • Option 1 - if you just want to read some text: Use speech to text

    please refer this answer

    Text to speech is built into Android 1.6+. Here is a simple example of how to do it.

    TextToSpeech tts = new TextToSpeech(this, this);
    tts.setLanguage(Locale.US);
    tts.speak("Text to say aloud", TextToSpeech.QUEUE_ADD, null);
    

    More info: http://android-developers.blogspot.com/2009/09/introduction-to-text-to-speech-in.html

    Option 2 - If you are particulate about using talkback

    refer to this answer

    Settings.Secure.putString(getContentResolver(), 
        Settings.Secure.ENABLED_ACCESSIBILITY_SERVICES, "pkgname/classname");
    Settings.Secure.putString(getContentResolver(), 
        Settings.Secure.ACCESSIBILITY_ENABLED, "1");
    

    Where the pkgname is your package name and the classname is the class name of your accessibility service.

    If you need to enable several services or you don't want to destory the previous settings you might want to use : to seperate other services.

    Also you might need to run as a system application and you might need the following permissions

    <uses-permission android:name="android.permission.WRITE_SETTINGS" />
    <uses-permission android:name="android.permission.WRITE_SECURE_SETTINGS" />
    

    this might not work on some versions of Android.

    Also refer other answers to this question

    PS. If it doesn't work, maybe you could find some luck in /data/data/com.android.providers.settings/databases/settings.db/secure, that's where Android stores secure settings.