Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to check if Talkback is active in JellyBean

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.

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?

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>

like image 715
pandre Avatar asked Nov 29 '22 02:11

pandre


1 Answers

This can be achieved much easier by using AccessibilityManager.

AccessibilityManager am = (AccessibilityManager) getSystemService(ACCESSIBILITY_SERVICE);
boolean isAccessibilityEnabled = am.isEnabled();
boolean isExploreByTouchEnabled = am.isTouchExplorationEnabled();
like image 170
caseyburkhardt Avatar answered Dec 04 '22 22:12

caseyburkhardt