gpt4 book ai didi

安卓辅助功能 : Reading custom text on activity launch

转载 作者:搜寻专家 更新时间:2023-11-01 07:46:55 26 4
gpt4 key购买 nike

我想在“我的 Activity ”启动后立即通过辅助功能阅读一些说明。我怎样才能做到这一点? (我不想读出 Activity 标签)

最佳答案

您可以通过发布无障碍通告 Activity 来做到这一点。

AccessibilityManager manager = (AccessibilityManager)mService.getSystemService(Context.ACCESSIBILITY_SERVICE);

if (manager.isEnabled()) {

AccessibilityEvent e = AccessibilityEvent.obtain();
e.setEventType(AccessibilityEvent.TYPE_ANNOUNCEMENT);
e.getText().add(message);

//There may be other things you need to add like class/packagename, I'm doing this from memory on my non-dev machine, so if this isn't quite right I apologize, I promise it's super close! :)

manager.sendAccessibilityEvent(e);
}

请注意,您可能无法在 Activity 的 onCreate 方法中执行此操作。无障碍服务的附件存在微妙的竞争条件。如果确实将它放在 onCreate 中不起作用,请尝试将其延迟添加到 Runnable 或 onPostResume 中,我认为这是该链中的最新回调。但最终,如果这是一个问题,延迟的 Runnable 是唯一可靠的解决方法。

关于安卓辅助功能 : Reading custom text on activity launch,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42154422/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com