Emin Çiftçi
Emin Çiftçi

Reputation: 139

Disable talkback with code

I built an application for blind people. It runs with text to speech. When I open talkback, my app does not run, lockes on logo screen. What I looking for is when my app runs talkback would stop.

Upvotes: 0

Views: 1718

Answers (1)

ataulm
ataulm

Reputation: 15334

It's not possible to turn TalkBack on or off from within your app unless you have been granted the system permission WRITE_SECURE_SETTINGS (via ADB) by the user.

private static final String TALKBACK_SERVICE_NAME = "com.google.android.marvin.talkback/.TalkBackService";

private void updateTalkBackState(boolean enableTalkBack) {
    if (enableTalkBack) {
        enableAccessibilityService(TALKBACK_SERVICE_NAME);
    } else {
        disableAccessibilityServices();
    }
}

private void enableAccessibilityService(String name) {
    Settings.Secure.putString(getContentResolver(), Settings.Secure.ENABLED_ACCESSIBILITY_SERVICES, name);
    Settings.Secure.putString(getContentResolver(), Settings.Secure.ACCESSIBILITY_ENABLED, VALUE_ENABLED);
}

private void disableAccessibilityServices() {
    Settings.Secure.putString(getContentResolver(), Settings.Secure.ENABLED_ACCESSIBILITY_SERVICES, "");
    Settings.Secure.putString(getContentResolver(), Settings.Secure.ACCESSIBILITY_ENABLED, VALUE_DISABLED);
}

Upvotes: 1

Related Questions