Disable talkback with code

。_饼干妹妹 提交于 2019-12-02 23:47:11

问题


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.


回答1:


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);
}


来源:https://stackoverflow.com/questions/42963865/disable-talkback-with-code

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!