How to Know If Android Talkback Is Active

How to know if Android TalkBack is active?

For an example, look at isScreenReaderActive() in HomeLauncher.java file in the Eyes-Free shell application (via groups thread).

To sum up: you detect all screen readers with Intents, then query the status provider of each to see if it is active.

If you really want to limit it to TalkBack only, you could try checking the ResolveInfo.serviceInfo.packageName for each result returned from queryIntentServices() to see if it matches the TalkBack package.

How to check if Talkback is active in JellyBean

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

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

How to detect when user turns on/off talkback in android programmatically

You can use AccessibilityManager.AccessibilityStateChangeListener to receive whether listen to changes in Accessibilty Service.

Unfortunately this will be true if ANY of the accessibility services are enabled.

AccessibilityManager accessibilityManager= (AccessibilityManager) getSystemService(Context.ACCESSIBILITY_SERVICE);

// Put this in onCreate
accessibilityManager.addAccessibilityStateChangeListener(new AccessibilityManager.AccessibilityStateChangeListener() {
@Override
public void onAccessibilityStateChanged(boolean b) {
accessibilityChanged(b);
}
});
accessibiltyChanged(accessibiltyManager.isEnabled());

void accessibiltyChanged (Boolean enabled) {
// Do your stuff
}

You can also try using getEnabledAccessibilityServiceList. This will return the list of all active accessibility services. But this will not be a listener meaning you'll not get a callback if this changes. A hack would be to call this function at regular intervals to check if anything has changed.



Related Topics



Leave a reply



Submit