Android TalkBack: Is there a Listener to catch all Accessibility Events?

Viewed 5450

Background: What is the problem

My app has this acronym for a word let us assume it is

ABC

When I use Google's voice service it reads out the letters which is great

However when I use Samsung Voice (S Voice), it reads it out as 1 word which is not great!

So why not just set content descriptions?

ABC appears in many places, it is not viable to setup alternative content descriptions. Also it could break the content description for other voice over services that read it out correctly like Google's one

My Plan

So I had an issue a while back and I found this great method for classes that extend ViewGroup which was onRequestSendAccessibilityEvent. To sum up, this method allows you to catch a AccessibilityEvent to modify it in some way before it is processed. Among other things you can grab the content description to be read out and modify it.

My idea is to obtain what the current TTS or TalkBack service engine is being used and use regex to edit a content description for the letters ABC and make it A B C if it Samsung Voice (S Voice). Hopefully!

My question

Anyone know a listener or callback to get the AccessibilityEvent to be processed in a global or generic case? onRequestSendAccessibilityEvent is only for ViewGroup. I could not find an alternative for Activity.

Anyone know how to catch all incoming AccessibilityEvent or maybe an alternative solution to my problem

Thanks for reading!

2 Answers

You can use ViewCompat delegate as well. In fact, the above solution did not work for me.

ViewCompat.setAccessibilityDelegate(contentView, object : AccessibilityDelegateCompat() {
     override fun onInitializeAccessibilityNodeInfo(v: View, info: AccessibilityNodeInfoCompat) {
             super.onInitializeAccessibilityNodeInfo(v, info)
             Log.d("zcz", "sdfsdf")
      }
})
Related