使用代码禁用对讲

时间:2017-03-22 22:30:42

标签: android talkback

我为盲人建立了一个应用程序。它以文本到语音运行。当我打开对讲时,我的应用程序无法运行,锁定徽标屏幕。我想要的是当我的应用运行时,对讲会停止。

1 个答案:

答案 0 :(得分:0)

除非您已被用户授予系统权限WRITE_SECURE_SETTINGS(通过ADB),否则无法在应用内打开或关闭TalkBack。

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