这个问题询问如何知道Android Talkback是否处于活动状态;这在Jelly Bean之前有效。从Android 4.1开始,这些步骤不再适用,因为所提到的光标为空。
话虽如此,我想问的是,在Jelly Bean中是否有一种方法可以进行相同的检查。
编辑 我尝试搜索TalkBack代码,并在这里找到了它。 为了检查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>