如何检查是否对讲活跃在软糖 [英] How to check if Talkback is active in JellyBean

查看:175
本文介绍了如何检查是否对讲活跃在软糖的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这个问题问怎么知道的Andr​​oid对讲有效;这一直工作到果冻豆。从安卓4.1,该步骤不再工作开始,因为提到光标是空的。

This question asked how to know if Android Talkback is active; that worked until Jelly Bean. Starting from Android 4.1, that steps no longer work, because the mentioned cursor is empty.

有了这个说,我要问的是,如果有一种方法做同样的检查果冻豆。

Having this said, I want to ask is if there is a way to do the same checking in Jelly Bean.

修改 我试图寻找在对讲系统code,我发现它<一个href="http://eyes-free.google$c$c.com/svn-history/r729/trunk/TalkBack/src/com/google/android/marvin/talkback/"相对=nofollow>此处。 对于检查是否对讲系统活跃,我现在用的是下面的code:

EDIT I tried to search for TalkBack code and I found it here. For checking if TalkBack is active, I am using the following code:

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
}

有此表示,如果光标是空的,我们怎么知道,如果对讲系统运行?

Having this said, if the cursor is empty, how do we know if TalkBack is running?

编辑2 继@JoxTraex建议,我现在发送广播查询话语提示是否启用:

EDIT 2 Following @JoxTraex suggestions, I am now sending a broadcast to query whether or not TalkBack is enabled:

Intent i = new Intent();
i.setAction("com.google.android.marvin.talkback.ACTION_QUERY_TALKBACK_ENABLED_COMMAND");
sendBroadcast(i);

现在我应该怎么得到的反应如何?

Now how should I receive the response?

我尝试添加下面的体现,但我的接收器没有收到任何回复:

I tried adding the following to manifest, but my receiver does not receive any response:

<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>

推荐答案

我不知道这是实现什么建议的最佳方式,但我设法使这项工作通过以下code:

I'm not sure this is the best way of achieving what is proposed, but I managed to make this work by using the following code:

Intent screenReaderIntent = new Intent("android.accessibilityservice.AccessibilityService");
screenReaderIntent.addCategory("android.accessibilityservice.category.FEEDBACK_SPOKEN");
List<ResolveInfo> screenReaders = getPackageManager().queryIntentServices(screenReaderIntent, 0);
Cursor cursor = null;
int status = 0;
ContentResolver cr = getContentResolver();

List<String> runningServices = new ArrayList<String>();
ActivityManager manager = (ActivityManager) getSystemService(ACTIVITY_SERVICE);
for (RunningServiceInfo service : manager.getRunningServices(Integer.MAX_VALUE)) {
    runningServices.add(service.service.getPackageName());
}

for (ResolveInfo screenReader : screenReaders) {
    cursor = cr.query(Uri.parse("content://" + screenReader.serviceInfo.packageName
            + ".providers.StatusProvider"), null, null, null, null);

    if (cursor != null && cursor.moveToFirst()) { //this part works for Android <4.1
        status = cursor.getInt(0);
        cursor.close();
        if (status == 1) {
            //screen reader active!
        } else {
            //screen reader inactive
        }
    } else {  //this part works for Android 4.1+
        if (runningServices.contains(screenReader.serviceInfo.packageName)) {
            //screen reader active!
        } else {
            //screen reader inactive
        }
    }
}

也许这是不是最好的方式,但它是唯一一个我能想到的,工作在果冻豆和previous的Andr​​oid版本

Probably this is not the best way but it is the only one I can think of that works in Jelly Bean and in previous Android versions

这篇关于如何检查是否对讲活跃在软糖的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆