1

I am trying to make a phone number a link on Android, but for some reason, one of the testers is seeing an issue where the phone number is not a link on two different devices while another tester and a developer are not seeing the issue. Could it be some kind of device configuration that disables links? Here is my code:

textView.AutoLinkMask = Android.Text.Util.MatchOptions.PhoneNumbers;

Result on one person's Samsung S9 Plus and S20 (both Android 10):

No Link

Result on two different people devices, one tested on a Samsung S10 and the other on a Note 9 (both Android 10):

Phone Link

I also tried on Samsung S9 Plus and S20 emulators and it worked. Which makes me think it has something to do with those specific devices, maybe some setting?

Marcelo
  • 217
  • 1
  • 2
  • 11

1 Answers1

1

If I use device that don't having SIM card, I encounter the same problem, so please make sure your phone is plugged into sim card.

 private static void gatherTelLinks(ArrayList<LinkSpec> links, Spannable s,
        @Nullable Context context) {
    PhoneNumberUtil phoneUtil = PhoneNumberUtil.getInstance();
    final TelephonyManager tm = (context == null)
            ? TelephonyManager.getDefault()
            : TelephonyManager.from(context);
    Iterable<PhoneNumberMatch> matches = phoneUtil.findNumbers(s.toString(),
            tm.getSimCountryIso().toUpperCase(Locale.US),
            Leniency.POSSIBLE, Long.MAX_VALUE);
    for (PhoneNumberMatch match : matches) {
        LinkSpec spec = new LinkSpec();
        spec.url = "tel:" + PhoneNumberUtils.normalizeNumber(match.rawString());
        spec.start = match.start();
        spec.end = match.end();
        links.add(spec);
    }
}

The phoneUtil.findNumbers function is passed in getSimCountryIso(), if the device don't have sim card, this method may have problem.

The same thread you can take a look:

android:autoLink for phone numbers doesn't always work

Cherry Bu - MSFT
  • 10,160
  • 1
  • 10
  • 16
  • Thank you! That helps a lot – Marcelo Nov 02 '20 at 17:18
  • I saw that post, but for some reason I did not see this part you just sent, I assumed the topic was about recognizing phone numbers with different lengths. Thank you again, that helps a lot =) – Marcelo Nov 02 '20 at 17:24