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 curs
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 screenReaders = getPackageManager().queryIntentServices(screenReaderIntent, 0);
Cursor cursor = null;
int status = 0;
ContentResolver cr = getContentResolver();
List runningServices = new ArrayList();
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