如何在JellyBean中检查Talkback是否处于活动状态

pan*_*dre 4 android accessibility talkback android-4.1-jelly-bean

这个问题询问如何知道Android Talkback是否有效; 直到果冻豆工作.从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
}
Run Code Online (Sandbox Code Playgroud)

有了这个说,如果光标为空,我们怎么知道TalkBack是否正在运行?

编辑2 在@JoxTraex建议之后,我现在发送广播来查询是否启用了TalkBack:

Intent i = new Intent();
i.setAction("com.google.android.marvin.talkback.ACTION_QUERY_TALKBACK_ENABLED_COMMAND");
sendBroadcast(i);
Run Code Online (Sandbox Code Playgroud)

现在我应该如何收到回复?

我尝试将以下内容添加到清单中,但我的接收方没有收到任何响应:

<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>
Run Code Online (Sandbox Code Playgroud)

小智 19

使用可以更容易地实现这一点AccessibilityManager.

AccessibilityManager am = (AccessibilityManager) getSystemService(ACCESSIBILITY_SERVICE);
boolean isAccessibilityEnabled = am.isEnabled();
boolean isExploreByTouchEnabled = am.isTouchExplorationEnabled();
Run Code Online (Sandbox Code Playgroud)