【发布时间】:2012-08-03 14:58:24
【问题描述】:
This question 询问如何知道 Android Talkback 是否处于活动状态;直到果冻豆为止。从 Android 4.1 开始,这些步骤不再起作用,因为提到的光标是空的。
话虽如此,我想问的是是否有办法在 Jelly Bean 中进行相同的检查。
编辑 我试图搜索 TalkBack 代码并找到它here。 为了检查 TalkBack 是否处于活动状态,我使用以下代码:
Intent screenReaderIntent = new Intent("android.accessibilityservice.AccessibilityService");
screenReaderIntent.addCategory("android.accessibilityservice.category.FEEDBACK_SPOKEN");
List<ResolveInfo> screenReaders = getPackageManager().queryIntentServices(screenReaderIntent, 0);
Cursor cursor = null;
ContentResolver cr = getContentResolver();
for (ResolveInfo screenReader : screenReaders) {
cursor = cr.query(Uri.parse("content://" + screenReader.serviceInfo.packageName
+ ".providers.StatusProvider"), null, null, null, null);
//here, cursor is not null, but calling cursor.moveToFirst() returns false, which means the cursor is empty
}
话虽如此,如果光标为空,我们如何知道 TalkBack 是否正在运行?
编辑 2 根据@JoxTraex 的建议,我现在发送一个广播来查询是否启用了 TalkBack:
Intent i = new Intent();
i.setAction("com.google.android.marvin.talkback.ACTION_QUERY_TALKBACK_ENABLED_COMMAND");
sendBroadcast(i);
现在我应该如何接收响应?
我尝试将以下内容添加到清单中,但我的接收器没有收到任何响应:
<receiver android:name="my.package.MyBroadcastReceiver"
android:permission="com.google.android.marvin.talkback.PERMISSION_SEND_INTENT_BROADCAST_COMMANDS_TO_TALKBACK">
<intent-filter>
<action android:name="com.google.android.marvin.talkback.ACTION_QUERY_TALKBACK_ENABLED_COMMAND" />
</intent-filter>
【问题讨论】:
-
我的建议是浏览 AOSP 源代码,看看哪些 API 用于 TalkBack。 TalkBack 的源代码是否可用。
-
@JoxTraex 感谢您的回复。我用新信息编辑了帖子,您有什么建议吗?
标签: android accessibility talkback android-4.1-jelly-bean