14

I have a string "9039662543", and when talk back is on, this string is read as "nine million...." in 4.3 android devices, above 4.3 devices its working fine, by reading "nine zero three...". What should I do to fix this?

7 Answers7

10

I'm assuming this is a phone number? I can't tell because there is no formatting. Which is the heart of the problem. There are multiple fixes for this.

A: Leave it alone. TalkBack users have the option of parsing elements by view, paragraph, sentence, word, character, etc. If a user can't tell it's a phone number by the context, you need more context. The number itself is fine!

B: Format it better. (903)-966-2542 vs 9039662543, without any additional context, are two different pieces of information. It may still read out as something like "Parentheses nine-hundread and three........" but it will be more obvious it is a phone number, and the chunks are easy to keep track of. Sorry I dno't have a pre 4.3 device to check out what the actual announcement is.

C: Override the content description. If the text representation is:

Text: 9039662543 Content Description: 9 0 3 9 6 6 2 5 4 3

I recommend against this approach. These two values are not the same. Just because you are uncomfortable with the announcement doesn't mean a TalkBack user would be. As you get accustomed to using TalkBack you get accustom to switching to different text parsing modes. A user who doesn't care about the phone number would be frustrated by the slower read out of the separated version. Leave them the option of ignoring it, and having it blow by quickly in the more compressed form. Also, informatively, if there is no context those two numbers don't really represent the same thing. The solution in this case is provide this context NOT to change the presentation. Separate is NOT equal.

MobA11y
  • 18,425
  • 3
  • 49
  • 76
2

For EditText, add a space between characters and set this text in Accessibility Node Info.

ViewCompat.setAccessibilityDelegate(editText,object : AccessibilityDelegateCompat(){
    override fun onInitializeAccessibilityNodeInfo(host: View, info: AccessibilityNodeInfoCompat) {
        super.onInitializeAccessibilityNodeInfo(host, info)
        info.text = editText.text.toString().replace(".".toRegex(),"$0 ")
    }
})
kiran puppala
  • 689
  • 8
  • 17
  • I liked this solution we can use it in different situations like saying the contract number too. val contractNumber = "64583658" val text = "Contract Number $contractNumber" val contentDescriptionText = "Contract Number ${contractNumber.replace(".".toRegex(),"$0 ")}" Not to mention it's easy to implement. – Lucas Batista Jan 17 '22 at 13:53
1

While I see multiple people recommending what ChrisCM has posted. I see that the default contacts application does this differently.

The default contact application reads the phone number digit-by-digit. It also does a little more than that and it can be reused. The API that is used is:

https://developer.android.com/reference/android/telephony/PhoneNumberUtils.html#createTtsSpan(java.lang.String)

The details of how it works could be found here :

https://android.googlesource.com/platform/frameworks/base/+/master/telephony/java/android/telephony/PhoneNumberUtils.java

Ahmed Zayed
  • 2,165
  • 1
  • 20
  • 21
RocketRandom
  • 1,102
  • 7
  • 20
0
//add extra space to text and set that text as contentDescription
textView.setText(readbleText);
StringBuilder builder = new StringBuilder();
for (int i = 0; i < readbleText.length(); i++) {
builder.append(readbleText.charAt(i));
builder.append("\u00A0");
}
textView.setContentDescription(builder);
  • this was already suggested in option C by @ChrisCM and i agree that this would be the least desirable solution. not only does it slow the screen reader down, but it makes braille devices display a bunch of spaces between numbers. – slugolicious Feb 05 '19 at 15:41
0

Make sure the input type on the edittext is phone and not number:

android:inputType="phone"

and not:

android:inputType="number"
Thiago
  • 12,778
  • 14
  • 93
  • 110
  • Sometimes you want a number keyboard but the content is phone number, so this wont work. – Saba Apr 29 '21 at 13:37
0

I know it's already answered but inspired by this answer I wrote an extension function for textView (in Kotlin of course ) which can be re-used as a utility function overall by those who might have this problem.

fun TextView.separateText() {
val textView = this
ViewCompat.setAccessibilityDelegate(textView, object : AccessibilityDelegateCompat() {
    override fun onInitializeAccessibilityNodeInfo(
        host: View,
        info: AccessibilityNodeInfoCompat
    ) {
        super.onInitializeAccessibilityNodeInfo(host, info)
        info.text = textView.text.toString().replace(".".toRegex(), "$0 ")
    }
})

}

PS: I was not able to post this under his/her answer, because I do not enough reputation.

moonkin
  • 353
  • 1
  • 10
-1

You can add zero-width non-breaking space characters "\ufeff" to separate the numbers invisibly. It will read the number as digits. Do refer the comment in the below link for more details How to change Android Talkback in case of App name

Nivashini
  • 9
  • 5
  • @GeorgeZ. The answer is _"You can add zero-width non-breaking space characters "\ufeff" to separate the numbers invisibly."_, while the link is provided for additional reference. This is not a link-only answer. – Mark Rotteveel Oct 13 '19 at 10:17