android:autoLink for phone numbers doesn't always work












12















I have a simple TextView with local phone number 852112222 or (8 5) 211 2222.



I need it to be clickable, so naturally I used android:autoLink="all".

But for some reason I don't understand same phone number is not "linkified" on all devices.



On plain Genymotion device it didn't work. On my personal OnePlus2 device it worked.
Tested on bunch on different devices - no luck.



What could be the issue?

User account preferences? Android version? ORM? Something else?










share|improve this question



























    12















    I have a simple TextView with local phone number 852112222 or (8 5) 211 2222.



    I need it to be clickable, so naturally I used android:autoLink="all".

    But for some reason I don't understand same phone number is not "linkified" on all devices.



    On plain Genymotion device it didn't work. On my personal OnePlus2 device it worked.
    Tested on bunch on different devices - no luck.



    What could be the issue?

    User account preferences? Android version? ORM? Something else?










    share|improve this question

























      12












      12








      12


      1






      I have a simple TextView with local phone number 852112222 or (8 5) 211 2222.



      I need it to be clickable, so naturally I used android:autoLink="all".

      But for some reason I don't understand same phone number is not "linkified" on all devices.



      On plain Genymotion device it didn't work. On my personal OnePlus2 device it worked.
      Tested on bunch on different devices - no luck.



      What could be the issue?

      User account preferences? Android version? ORM? Something else?










      share|improve this question














      I have a simple TextView with local phone number 852112222 or (8 5) 211 2222.



      I need it to be clickable, so naturally I used android:autoLink="all".

      But for some reason I don't understand same phone number is not "linkified" on all devices.



      On plain Genymotion device it didn't work. On my personal OnePlus2 device it worked.
      Tested on bunch on different devices - no luck.



      What could be the issue?

      User account preferences? Android version? ORM? Something else?







      android linkify






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked Nov 24 '16 at 14:14









      Martynas JurkusMartynas Jurkus

      3,84294588




      3,84294588
























          7 Answers
          7






          active

          oldest

          votes


















          15





          +50









          Here is my investigation.



          I created a new project, and added android:autoLink="all" to a text view in activity_main.xml. Thanks to the developers of Android Studio, I could see the preview, and I found something interesting:





          • 12345 not linked


          • 123456 not linked


          • 1234567 linked


          • 12345678 linked


          • 123456789 not linked


          • 1234567890 not likned


          • 12345678901 linked


          • 123456789012 not linked


          The result is the same on my phone. So I looked into the source code, searched for the keyword autolink, then I found this:



          private void setText(CharSequence text, BufferType type,
          boolean notifyBefore, int oldlen) {

          ...
          // unconcerned code above

          if (mAutoLinkMask != 0) {
          Spannable s2;

          if (type == BufferType.EDITABLE || text instanceof Spannable) {
          s2 = (Spannable) text;
          } else {
          s2 = mSpannableFactory.newSpannable(text);
          }

          if (Linkify.addLinks(s2, mAutoLinkMask)) {
          text = s2;
          type = (type == BufferType.EDITABLE) ? BufferType.EDITABLE : BufferType.SPANNABLE;

          /*
          * We must go ahead and set the text before changing the
          * movement method, because setMovementMethod() may call
          * setText() again to try to upgrade the buffer type.
          */
          mText = text;

          // Do not change the movement method for text that support text selection as it
          // would prevent an arbitrary cursor displacement.
          if (mLinksClickable && !textCanBeSelected()) {
          setMovementMethod(LinkMovementMethod.getInstance());
          }
          }
          }

          ...
          // unconcerned code above
          }


          So the keyword is Linkify now. For addLinks:



          public static final boolean addLinks(@NonNull Spannable text, @LinkifyMask int mask) {
          ...

          if ((mask & PHONE_NUMBERS) != 0) {
          gatherTelLinks(links, text);
          }

          ...
          }

          private static final void gatherTelLinks(ArrayList<LinkSpec> links, Spannable s) {
          PhoneNumberUtil phoneUtil = PhoneNumberUtil.getInstance();
          Iterable<PhoneNumberMatch> matches = phoneUtil.findNumbers(s.toString(),
          Locale.getDefault().getCountry(), 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);
          }
          }


          Then, something bad happened, the SDK doesn't have PhoneNumberUtil, specifically these 3 classes below:



          import com.android.i18n.phonenumbers.PhoneNumberMatch;
          import com.android.i18n.phonenumbers.PhoneNumberUtil;
          import com.android.i18n.phonenumbers.PhoneNumberUtil.Leniency;


          For now, the first reason surfaced: Locale.getDefault().getCountry().

          So I went to setting, found language, selected Chinese. The result is below:





          • 12345 linked


          • 123456 linked


          • 1234567 linked


          • 12345678 linked


          • 123456789 linked


          • 1234567890 linked


          • 12345678901 linked


          • 123456789012 linked


          Secondly, for the package of com.android.i18n.phonenumbers, I found this:
          https://android.googlesource.com/platform/external/libphonenumber/+/ics-factoryrom-2-release/java/src/com/android/i18n/phonenumbers

          If you are interested, check the link above. Notice in the URL: ics-factoryrom-2-release. So I highly doubt that this is platform-dependent.



          For the solution, CleverAndroid is right, taking full control of LinkMovementMethod is a good option.






          share|improve this answer

































            5














            Can you please try below code. Set attribute programmatically.



            Activity



            package custom.com.android_lab;

            import android.app.Activity;
            import android.os.Bundle;
            import android.text.util.Linkify;
            import android.widget.TextView;

            /**
            * You can use Activity or AppCompatActivity
            */
            public class MainActivity extends Activity {

            @Override
            protected void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);

            setContentView(R.layout.activity_main);

            // local phone number 852112222 or (8 5) 211 2222.

            // Tested OK!
            TextView textView1 = (TextView) findViewById(R.id.textv1);
            textView1.setAutoLinkMask(Linkify.PHONE_NUMBERS);
            textView1.setText("852112222");

            // Tested OK!
            TextView textView2 = (TextView) findViewById(R.id.textv2);
            textView2.setAutoLinkMask(Linkify.PHONE_NUMBERS);
            textView2.setText("(85) 211-2222");

            // Tested Failed!
            // Reason : Need to apply setAutoLinkMask prior to apply setText
            TextView textView3 = (TextView) findViewById(R.id.textv3);
            textView3.setText("852112222");
            textView2.setAutoLinkMask(Linkify.PHONE_NUMBERS);

            }
            }


            View



            <?xml version="1.0" encoding="utf-8"?>
            <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
            android:id="@+id/activity_main"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:orientation="vertical">

            <TextView
            android:id="@+id/textv1"
            android:layout_width="match_parent"
            android:layout_height="wrap_content" />

            <TextView
            android:id="@+id/textv2"
            android:layout_width="match_parent"
            android:layout_height="wrap_content" />

            <TextView
            android:id="@+id/textv3"
            android:layout_width="match_parent"
            android:layout_height="55dp" />

            </LinearLayout>


            enter image description here



            Testing Devices




            1. One plus one with Android 7.1

            2. Genymotion. 4.1.1 - API 16






            share|improve this answer


























            • Still same result. On some devices same number is linkified on other it does not. And it doesn't matter if I use Linkify.PHONE_NUMBERS or Linkify.ALL

              – Martynas Jurkus
              Nov 28 '16 at 10:19











            • Everything seems working fine here. Let me know your feedback.

              – young
              Nov 29 '16 at 10:01











            • Took your sample code - no luck. imgur.com/cSLuOdt Used same devices, even other SDK versions. Same result.

              – Martynas Jurkus
              Nov 29 '16 at 11:41













            • @MartynasJurkus Your image shown that second one was partially linkified

              – young
              Nov 29 '16 at 11:45













            • okay! will check one more time and let me know if you fix this.

              – young
              Nov 29 '16 at 11:51



















            5














            Just do the following



            TextView userInput= (TextView) view.findViewById(R.id.textView);

            if(userInput != null){
            Linkify.addLinks(userInput, Patterns.PHONE,"tel:",Linkify.sPhoneNumberMatchFilter,Linkify.sPhoneNumberTransformFilter);
            userInput.setMovementMethod(LinkMovementMethod.getInstance());
            }


            and also remove the



            android:autoLink


            from your xml file






            share|improve this answer































              4














              I have seen a lot of inconsistencies when using auto link. If at all you are working for a prod version. Always go for SpannableStringBuilder with LinkMovementMethod. You have good control of how the text needs to be displayed.



              The snippet below may help.



              String phone = "your phone number";
              String message = "Phone number is: ";

              Spannable span = new SpannableString(String.format("%sn%s",message, phone));
              ForegroundColorSpan color = new ForegroundColorSpan(Res.color(R.color.blue));
              ClickableSpan click = new ClickableSpan() {
              @Override
              public void onClick(View widget) {
              Navigator.dialer("your phone number");
              }
              public void updateDrawState(TextPaint ds) {// override updateDrawState
              ds.setUnderlineText(false); // set to false to remove underline
              }
              };

              span.setSpan(color, message.length(), message.length() + phone.length() + 1, Spanned.SPAN_INCLUSIVE_INCLUSIVE);
              span.setSpan(click, message.length(), message.length() + phone.length() + 1, Spanned.SPAN_INCLUSIVE_INCLUSIVE);

              changesMessageLabel.setText(span);
              changesMessageLabel.setMovementMethod(LinkMovementMethod.getInstance());





              share|improve this answer































                4














                I would suggest you just to add country code and all your issue will be resolved,



                android:autoLink="phone"
                android:text="+91-8000000000"


                If we add country code before the number, then no need of other temporary solutions.






                share|improve this answer
























                • That would work. Although phone numbers is user input and it is not common practice to enter country codes when entering same country phone number so I can't force validation on them.

                  – Martynas Jurkus
                  Feb 26 '18 at 7:57











                • Adding Country Code will help developer to resolve, future issues when his/her Android App is used globally. In that case, user will not be able to make a call due to no country code (Invalid number). So, why not add it beforehand to resolve future issues, and this approach will even help developer from adding other temporary solutions to make android:autoLink work.

                  – miPlodder
                  Feb 27 '18 at 7:03








                • 1





                  Just to confirm, this worked for me

                  – Ivan Milisavljevic
                  Nov 11 '18 at 19:24



















                1














                For phone autolink specific you should use



                android:autoLink="phone"


                For more refer: textview autolink






                share|improve this answer
























                • Why? android:autoLink="phone" should work too. And it works on some devices. And that wasn't the question.

                  – Martynas Jurkus
                  Nov 24 '16 at 15:59





















                1














                Harsh Agrawal answer worked for me in cases where the phone number is 11 digits or more with 3 blocks. e.g. 123 456 78910



                TextView textView = findViewById(R.id.text_view);
                textView.setText("123 456 78910");
                Linkify.addLinks(textView, Patterns.PHONE, "tel:", Linkify.sPhoneNumberMatchFilter,
                Linkify.sPhoneNumberTransformFilter);


                I had to call Linkify.addLinks after setting text for it to work.



                Note that Linkify.addLinks already calls setMovementMethod on the text view.






                share|improve this answer























                  Your Answer






                  StackExchange.ifUsing("editor", function () {
                  StackExchange.using("externalEditor", function () {
                  StackExchange.using("snippets", function () {
                  StackExchange.snippets.init();
                  });
                  });
                  }, "code-snippets");

                  StackExchange.ready(function() {
                  var channelOptions = {
                  tags: "".split(" "),
                  id: "1"
                  };
                  initTagRenderer("".split(" "), "".split(" "), channelOptions);

                  StackExchange.using("externalEditor", function() {
                  // Have to fire editor after snippets, if snippets enabled
                  if (StackExchange.settings.snippets.snippetsEnabled) {
                  StackExchange.using("snippets", function() {
                  createEditor();
                  });
                  }
                  else {
                  createEditor();
                  }
                  });

                  function createEditor() {
                  StackExchange.prepareEditor({
                  heartbeatType: 'answer',
                  autoActivateHeartbeat: false,
                  convertImagesToLinks: true,
                  noModals: true,
                  showLowRepImageUploadWarning: true,
                  reputationToPostImages: 10,
                  bindNavPrevention: true,
                  postfix: "",
                  imageUploader: {
                  brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
                  contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
                  allowUrls: true
                  },
                  onDemand: true,
                  discardSelector: ".discard-answer"
                  ,immediatelyShowMarkdownHelp:true
                  });


                  }
                  });














                  draft saved

                  draft discarded


















                  StackExchange.ready(
                  function () {
                  StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f40788608%2fandroidautolink-for-phone-numbers-doesnt-always-work%23new-answer', 'question_page');
                  }
                  );

                  Post as a guest















                  Required, but never shown

























                  7 Answers
                  7






                  active

                  oldest

                  votes








                  7 Answers
                  7






                  active

                  oldest

                  votes









                  active

                  oldest

                  votes






                  active

                  oldest

                  votes









                  15





                  +50









                  Here is my investigation.



                  I created a new project, and added android:autoLink="all" to a text view in activity_main.xml. Thanks to the developers of Android Studio, I could see the preview, and I found something interesting:





                  • 12345 not linked


                  • 123456 not linked


                  • 1234567 linked


                  • 12345678 linked


                  • 123456789 not linked


                  • 1234567890 not likned


                  • 12345678901 linked


                  • 123456789012 not linked


                  The result is the same on my phone. So I looked into the source code, searched for the keyword autolink, then I found this:



                  private void setText(CharSequence text, BufferType type,
                  boolean notifyBefore, int oldlen) {

                  ...
                  // unconcerned code above

                  if (mAutoLinkMask != 0) {
                  Spannable s2;

                  if (type == BufferType.EDITABLE || text instanceof Spannable) {
                  s2 = (Spannable) text;
                  } else {
                  s2 = mSpannableFactory.newSpannable(text);
                  }

                  if (Linkify.addLinks(s2, mAutoLinkMask)) {
                  text = s2;
                  type = (type == BufferType.EDITABLE) ? BufferType.EDITABLE : BufferType.SPANNABLE;

                  /*
                  * We must go ahead and set the text before changing the
                  * movement method, because setMovementMethod() may call
                  * setText() again to try to upgrade the buffer type.
                  */
                  mText = text;

                  // Do not change the movement method for text that support text selection as it
                  // would prevent an arbitrary cursor displacement.
                  if (mLinksClickable && !textCanBeSelected()) {
                  setMovementMethod(LinkMovementMethod.getInstance());
                  }
                  }
                  }

                  ...
                  // unconcerned code above
                  }


                  So the keyword is Linkify now. For addLinks:



                  public static final boolean addLinks(@NonNull Spannable text, @LinkifyMask int mask) {
                  ...

                  if ((mask & PHONE_NUMBERS) != 0) {
                  gatherTelLinks(links, text);
                  }

                  ...
                  }

                  private static final void gatherTelLinks(ArrayList<LinkSpec> links, Spannable s) {
                  PhoneNumberUtil phoneUtil = PhoneNumberUtil.getInstance();
                  Iterable<PhoneNumberMatch> matches = phoneUtil.findNumbers(s.toString(),
                  Locale.getDefault().getCountry(), 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);
                  }
                  }


                  Then, something bad happened, the SDK doesn't have PhoneNumberUtil, specifically these 3 classes below:



                  import com.android.i18n.phonenumbers.PhoneNumberMatch;
                  import com.android.i18n.phonenumbers.PhoneNumberUtil;
                  import com.android.i18n.phonenumbers.PhoneNumberUtil.Leniency;


                  For now, the first reason surfaced: Locale.getDefault().getCountry().

                  So I went to setting, found language, selected Chinese. The result is below:





                  • 12345 linked


                  • 123456 linked


                  • 1234567 linked


                  • 12345678 linked


                  • 123456789 linked


                  • 1234567890 linked


                  • 12345678901 linked


                  • 123456789012 linked


                  Secondly, for the package of com.android.i18n.phonenumbers, I found this:
                  https://android.googlesource.com/platform/external/libphonenumber/+/ics-factoryrom-2-release/java/src/com/android/i18n/phonenumbers

                  If you are interested, check the link above. Notice in the URL: ics-factoryrom-2-release. So I highly doubt that this is platform-dependent.



                  For the solution, CleverAndroid is right, taking full control of LinkMovementMethod is a good option.






                  share|improve this answer






























                    15





                    +50









                    Here is my investigation.



                    I created a new project, and added android:autoLink="all" to a text view in activity_main.xml. Thanks to the developers of Android Studio, I could see the preview, and I found something interesting:





                    • 12345 not linked


                    • 123456 not linked


                    • 1234567 linked


                    • 12345678 linked


                    • 123456789 not linked


                    • 1234567890 not likned


                    • 12345678901 linked


                    • 123456789012 not linked


                    The result is the same on my phone. So I looked into the source code, searched for the keyword autolink, then I found this:



                    private void setText(CharSequence text, BufferType type,
                    boolean notifyBefore, int oldlen) {

                    ...
                    // unconcerned code above

                    if (mAutoLinkMask != 0) {
                    Spannable s2;

                    if (type == BufferType.EDITABLE || text instanceof Spannable) {
                    s2 = (Spannable) text;
                    } else {
                    s2 = mSpannableFactory.newSpannable(text);
                    }

                    if (Linkify.addLinks(s2, mAutoLinkMask)) {
                    text = s2;
                    type = (type == BufferType.EDITABLE) ? BufferType.EDITABLE : BufferType.SPANNABLE;

                    /*
                    * We must go ahead and set the text before changing the
                    * movement method, because setMovementMethod() may call
                    * setText() again to try to upgrade the buffer type.
                    */
                    mText = text;

                    // Do not change the movement method for text that support text selection as it
                    // would prevent an arbitrary cursor displacement.
                    if (mLinksClickable && !textCanBeSelected()) {
                    setMovementMethod(LinkMovementMethod.getInstance());
                    }
                    }
                    }

                    ...
                    // unconcerned code above
                    }


                    So the keyword is Linkify now. For addLinks:



                    public static final boolean addLinks(@NonNull Spannable text, @LinkifyMask int mask) {
                    ...

                    if ((mask & PHONE_NUMBERS) != 0) {
                    gatherTelLinks(links, text);
                    }

                    ...
                    }

                    private static final void gatherTelLinks(ArrayList<LinkSpec> links, Spannable s) {
                    PhoneNumberUtil phoneUtil = PhoneNumberUtil.getInstance();
                    Iterable<PhoneNumberMatch> matches = phoneUtil.findNumbers(s.toString(),
                    Locale.getDefault().getCountry(), 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);
                    }
                    }


                    Then, something bad happened, the SDK doesn't have PhoneNumberUtil, specifically these 3 classes below:



                    import com.android.i18n.phonenumbers.PhoneNumberMatch;
                    import com.android.i18n.phonenumbers.PhoneNumberUtil;
                    import com.android.i18n.phonenumbers.PhoneNumberUtil.Leniency;


                    For now, the first reason surfaced: Locale.getDefault().getCountry().

                    So I went to setting, found language, selected Chinese. The result is below:





                    • 12345 linked


                    • 123456 linked


                    • 1234567 linked


                    • 12345678 linked


                    • 123456789 linked


                    • 1234567890 linked


                    • 12345678901 linked


                    • 123456789012 linked


                    Secondly, for the package of com.android.i18n.phonenumbers, I found this:
                    https://android.googlesource.com/platform/external/libphonenumber/+/ics-factoryrom-2-release/java/src/com/android/i18n/phonenumbers

                    If you are interested, check the link above. Notice in the URL: ics-factoryrom-2-release. So I highly doubt that this is platform-dependent.



                    For the solution, CleverAndroid is right, taking full control of LinkMovementMethod is a good option.






                    share|improve this answer




























                      15





                      +50







                      15





                      +50



                      15




                      +50





                      Here is my investigation.



                      I created a new project, and added android:autoLink="all" to a text view in activity_main.xml. Thanks to the developers of Android Studio, I could see the preview, and I found something interesting:





                      • 12345 not linked


                      • 123456 not linked


                      • 1234567 linked


                      • 12345678 linked


                      • 123456789 not linked


                      • 1234567890 not likned


                      • 12345678901 linked


                      • 123456789012 not linked


                      The result is the same on my phone. So I looked into the source code, searched for the keyword autolink, then I found this:



                      private void setText(CharSequence text, BufferType type,
                      boolean notifyBefore, int oldlen) {

                      ...
                      // unconcerned code above

                      if (mAutoLinkMask != 0) {
                      Spannable s2;

                      if (type == BufferType.EDITABLE || text instanceof Spannable) {
                      s2 = (Spannable) text;
                      } else {
                      s2 = mSpannableFactory.newSpannable(text);
                      }

                      if (Linkify.addLinks(s2, mAutoLinkMask)) {
                      text = s2;
                      type = (type == BufferType.EDITABLE) ? BufferType.EDITABLE : BufferType.SPANNABLE;

                      /*
                      * We must go ahead and set the text before changing the
                      * movement method, because setMovementMethod() may call
                      * setText() again to try to upgrade the buffer type.
                      */
                      mText = text;

                      // Do not change the movement method for text that support text selection as it
                      // would prevent an arbitrary cursor displacement.
                      if (mLinksClickable && !textCanBeSelected()) {
                      setMovementMethod(LinkMovementMethod.getInstance());
                      }
                      }
                      }

                      ...
                      // unconcerned code above
                      }


                      So the keyword is Linkify now. For addLinks:



                      public static final boolean addLinks(@NonNull Spannable text, @LinkifyMask int mask) {
                      ...

                      if ((mask & PHONE_NUMBERS) != 0) {
                      gatherTelLinks(links, text);
                      }

                      ...
                      }

                      private static final void gatherTelLinks(ArrayList<LinkSpec> links, Spannable s) {
                      PhoneNumberUtil phoneUtil = PhoneNumberUtil.getInstance();
                      Iterable<PhoneNumberMatch> matches = phoneUtil.findNumbers(s.toString(),
                      Locale.getDefault().getCountry(), 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);
                      }
                      }


                      Then, something bad happened, the SDK doesn't have PhoneNumberUtil, specifically these 3 classes below:



                      import com.android.i18n.phonenumbers.PhoneNumberMatch;
                      import com.android.i18n.phonenumbers.PhoneNumberUtil;
                      import com.android.i18n.phonenumbers.PhoneNumberUtil.Leniency;


                      For now, the first reason surfaced: Locale.getDefault().getCountry().

                      So I went to setting, found language, selected Chinese. The result is below:





                      • 12345 linked


                      • 123456 linked


                      • 1234567 linked


                      • 12345678 linked


                      • 123456789 linked


                      • 1234567890 linked


                      • 12345678901 linked


                      • 123456789012 linked


                      Secondly, for the package of com.android.i18n.phonenumbers, I found this:
                      https://android.googlesource.com/platform/external/libphonenumber/+/ics-factoryrom-2-release/java/src/com/android/i18n/phonenumbers

                      If you are interested, check the link above. Notice in the URL: ics-factoryrom-2-release. So I highly doubt that this is platform-dependent.



                      For the solution, CleverAndroid is right, taking full control of LinkMovementMethod is a good option.






                      share|improve this answer















                      Here is my investigation.



                      I created a new project, and added android:autoLink="all" to a text view in activity_main.xml. Thanks to the developers of Android Studio, I could see the preview, and I found something interesting:





                      • 12345 not linked


                      • 123456 not linked


                      • 1234567 linked


                      • 12345678 linked


                      • 123456789 not linked


                      • 1234567890 not likned


                      • 12345678901 linked


                      • 123456789012 not linked


                      The result is the same on my phone. So I looked into the source code, searched for the keyword autolink, then I found this:



                      private void setText(CharSequence text, BufferType type,
                      boolean notifyBefore, int oldlen) {

                      ...
                      // unconcerned code above

                      if (mAutoLinkMask != 0) {
                      Spannable s2;

                      if (type == BufferType.EDITABLE || text instanceof Spannable) {
                      s2 = (Spannable) text;
                      } else {
                      s2 = mSpannableFactory.newSpannable(text);
                      }

                      if (Linkify.addLinks(s2, mAutoLinkMask)) {
                      text = s2;
                      type = (type == BufferType.EDITABLE) ? BufferType.EDITABLE : BufferType.SPANNABLE;

                      /*
                      * We must go ahead and set the text before changing the
                      * movement method, because setMovementMethod() may call
                      * setText() again to try to upgrade the buffer type.
                      */
                      mText = text;

                      // Do not change the movement method for text that support text selection as it
                      // would prevent an arbitrary cursor displacement.
                      if (mLinksClickable && !textCanBeSelected()) {
                      setMovementMethod(LinkMovementMethod.getInstance());
                      }
                      }
                      }

                      ...
                      // unconcerned code above
                      }


                      So the keyword is Linkify now. For addLinks:



                      public static final boolean addLinks(@NonNull Spannable text, @LinkifyMask int mask) {
                      ...

                      if ((mask & PHONE_NUMBERS) != 0) {
                      gatherTelLinks(links, text);
                      }

                      ...
                      }

                      private static final void gatherTelLinks(ArrayList<LinkSpec> links, Spannable s) {
                      PhoneNumberUtil phoneUtil = PhoneNumberUtil.getInstance();
                      Iterable<PhoneNumberMatch> matches = phoneUtil.findNumbers(s.toString(),
                      Locale.getDefault().getCountry(), 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);
                      }
                      }


                      Then, something bad happened, the SDK doesn't have PhoneNumberUtil, specifically these 3 classes below:



                      import com.android.i18n.phonenumbers.PhoneNumberMatch;
                      import com.android.i18n.phonenumbers.PhoneNumberUtil;
                      import com.android.i18n.phonenumbers.PhoneNumberUtil.Leniency;


                      For now, the first reason surfaced: Locale.getDefault().getCountry().

                      So I went to setting, found language, selected Chinese. The result is below:





                      • 12345 linked


                      • 123456 linked


                      • 1234567 linked


                      • 12345678 linked


                      • 123456789 linked


                      • 1234567890 linked


                      • 12345678901 linked


                      • 123456789012 linked


                      Secondly, for the package of com.android.i18n.phonenumbers, I found this:
                      https://android.googlesource.com/platform/external/libphonenumber/+/ics-factoryrom-2-release/java/src/com/android/i18n/phonenumbers

                      If you are interested, check the link above. Notice in the URL: ics-factoryrom-2-release. So I highly doubt that this is platform-dependent.



                      For the solution, CleverAndroid is right, taking full control of LinkMovementMethod is a good option.







                      share|improve this answer














                      share|improve this answer



                      share|improve this answer








                      edited Sep 19 '18 at 3:50









                      Pang

                      6,9271664102




                      6,9271664102










                      answered Dec 3 '16 at 10:57









                      Chris WongChris Wong

                      34315




                      34315

























                          5














                          Can you please try below code. Set attribute programmatically.



                          Activity



                          package custom.com.android_lab;

                          import android.app.Activity;
                          import android.os.Bundle;
                          import android.text.util.Linkify;
                          import android.widget.TextView;

                          /**
                          * You can use Activity or AppCompatActivity
                          */
                          public class MainActivity extends Activity {

                          @Override
                          protected void onCreate(Bundle savedInstanceState) {
                          super.onCreate(savedInstanceState);

                          setContentView(R.layout.activity_main);

                          // local phone number 852112222 or (8 5) 211 2222.

                          // Tested OK!
                          TextView textView1 = (TextView) findViewById(R.id.textv1);
                          textView1.setAutoLinkMask(Linkify.PHONE_NUMBERS);
                          textView1.setText("852112222");

                          // Tested OK!
                          TextView textView2 = (TextView) findViewById(R.id.textv2);
                          textView2.setAutoLinkMask(Linkify.PHONE_NUMBERS);
                          textView2.setText("(85) 211-2222");

                          // Tested Failed!
                          // Reason : Need to apply setAutoLinkMask prior to apply setText
                          TextView textView3 = (TextView) findViewById(R.id.textv3);
                          textView3.setText("852112222");
                          textView2.setAutoLinkMask(Linkify.PHONE_NUMBERS);

                          }
                          }


                          View



                          <?xml version="1.0" encoding="utf-8"?>
                          <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
                          android:id="@+id/activity_main"
                          android:layout_width="match_parent"
                          android:layout_height="match_parent"
                          android:orientation="vertical">

                          <TextView
                          android:id="@+id/textv1"
                          android:layout_width="match_parent"
                          android:layout_height="wrap_content" />

                          <TextView
                          android:id="@+id/textv2"
                          android:layout_width="match_parent"
                          android:layout_height="wrap_content" />

                          <TextView
                          android:id="@+id/textv3"
                          android:layout_width="match_parent"
                          android:layout_height="55dp" />

                          </LinearLayout>


                          enter image description here



                          Testing Devices




                          1. One plus one with Android 7.1

                          2. Genymotion. 4.1.1 - API 16






                          share|improve this answer


























                          • Still same result. On some devices same number is linkified on other it does not. And it doesn't matter if I use Linkify.PHONE_NUMBERS or Linkify.ALL

                            – Martynas Jurkus
                            Nov 28 '16 at 10:19











                          • Everything seems working fine here. Let me know your feedback.

                            – young
                            Nov 29 '16 at 10:01











                          • Took your sample code - no luck. imgur.com/cSLuOdt Used same devices, even other SDK versions. Same result.

                            – Martynas Jurkus
                            Nov 29 '16 at 11:41













                          • @MartynasJurkus Your image shown that second one was partially linkified

                            – young
                            Nov 29 '16 at 11:45













                          • okay! will check one more time and let me know if you fix this.

                            – young
                            Nov 29 '16 at 11:51
















                          5














                          Can you please try below code. Set attribute programmatically.



                          Activity



                          package custom.com.android_lab;

                          import android.app.Activity;
                          import android.os.Bundle;
                          import android.text.util.Linkify;
                          import android.widget.TextView;

                          /**
                          * You can use Activity or AppCompatActivity
                          */
                          public class MainActivity extends Activity {

                          @Override
                          protected void onCreate(Bundle savedInstanceState) {
                          super.onCreate(savedInstanceState);

                          setContentView(R.layout.activity_main);

                          // local phone number 852112222 or (8 5) 211 2222.

                          // Tested OK!
                          TextView textView1 = (TextView) findViewById(R.id.textv1);
                          textView1.setAutoLinkMask(Linkify.PHONE_NUMBERS);
                          textView1.setText("852112222");

                          // Tested OK!
                          TextView textView2 = (TextView) findViewById(R.id.textv2);
                          textView2.setAutoLinkMask(Linkify.PHONE_NUMBERS);
                          textView2.setText("(85) 211-2222");

                          // Tested Failed!
                          // Reason : Need to apply setAutoLinkMask prior to apply setText
                          TextView textView3 = (TextView) findViewById(R.id.textv3);
                          textView3.setText("852112222");
                          textView2.setAutoLinkMask(Linkify.PHONE_NUMBERS);

                          }
                          }


                          View



                          <?xml version="1.0" encoding="utf-8"?>
                          <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
                          android:id="@+id/activity_main"
                          android:layout_width="match_parent"
                          android:layout_height="match_parent"
                          android:orientation="vertical">

                          <TextView
                          android:id="@+id/textv1"
                          android:layout_width="match_parent"
                          android:layout_height="wrap_content" />

                          <TextView
                          android:id="@+id/textv2"
                          android:layout_width="match_parent"
                          android:layout_height="wrap_content" />

                          <TextView
                          android:id="@+id/textv3"
                          android:layout_width="match_parent"
                          android:layout_height="55dp" />

                          </LinearLayout>


                          enter image description here



                          Testing Devices




                          1. One plus one with Android 7.1

                          2. Genymotion. 4.1.1 - API 16






                          share|improve this answer


























                          • Still same result. On some devices same number is linkified on other it does not. And it doesn't matter if I use Linkify.PHONE_NUMBERS or Linkify.ALL

                            – Martynas Jurkus
                            Nov 28 '16 at 10:19











                          • Everything seems working fine here. Let me know your feedback.

                            – young
                            Nov 29 '16 at 10:01











                          • Took your sample code - no luck. imgur.com/cSLuOdt Used same devices, even other SDK versions. Same result.

                            – Martynas Jurkus
                            Nov 29 '16 at 11:41













                          • @MartynasJurkus Your image shown that second one was partially linkified

                            – young
                            Nov 29 '16 at 11:45













                          • okay! will check one more time and let me know if you fix this.

                            – young
                            Nov 29 '16 at 11:51














                          5












                          5








                          5







                          Can you please try below code. Set attribute programmatically.



                          Activity



                          package custom.com.android_lab;

                          import android.app.Activity;
                          import android.os.Bundle;
                          import android.text.util.Linkify;
                          import android.widget.TextView;

                          /**
                          * You can use Activity or AppCompatActivity
                          */
                          public class MainActivity extends Activity {

                          @Override
                          protected void onCreate(Bundle savedInstanceState) {
                          super.onCreate(savedInstanceState);

                          setContentView(R.layout.activity_main);

                          // local phone number 852112222 or (8 5) 211 2222.

                          // Tested OK!
                          TextView textView1 = (TextView) findViewById(R.id.textv1);
                          textView1.setAutoLinkMask(Linkify.PHONE_NUMBERS);
                          textView1.setText("852112222");

                          // Tested OK!
                          TextView textView2 = (TextView) findViewById(R.id.textv2);
                          textView2.setAutoLinkMask(Linkify.PHONE_NUMBERS);
                          textView2.setText("(85) 211-2222");

                          // Tested Failed!
                          // Reason : Need to apply setAutoLinkMask prior to apply setText
                          TextView textView3 = (TextView) findViewById(R.id.textv3);
                          textView3.setText("852112222");
                          textView2.setAutoLinkMask(Linkify.PHONE_NUMBERS);

                          }
                          }


                          View



                          <?xml version="1.0" encoding="utf-8"?>
                          <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
                          android:id="@+id/activity_main"
                          android:layout_width="match_parent"
                          android:layout_height="match_parent"
                          android:orientation="vertical">

                          <TextView
                          android:id="@+id/textv1"
                          android:layout_width="match_parent"
                          android:layout_height="wrap_content" />

                          <TextView
                          android:id="@+id/textv2"
                          android:layout_width="match_parent"
                          android:layout_height="wrap_content" />

                          <TextView
                          android:id="@+id/textv3"
                          android:layout_width="match_parent"
                          android:layout_height="55dp" />

                          </LinearLayout>


                          enter image description here



                          Testing Devices




                          1. One plus one with Android 7.1

                          2. Genymotion. 4.1.1 - API 16






                          share|improve this answer















                          Can you please try below code. Set attribute programmatically.



                          Activity



                          package custom.com.android_lab;

                          import android.app.Activity;
                          import android.os.Bundle;
                          import android.text.util.Linkify;
                          import android.widget.TextView;

                          /**
                          * You can use Activity or AppCompatActivity
                          */
                          public class MainActivity extends Activity {

                          @Override
                          protected void onCreate(Bundle savedInstanceState) {
                          super.onCreate(savedInstanceState);

                          setContentView(R.layout.activity_main);

                          // local phone number 852112222 or (8 5) 211 2222.

                          // Tested OK!
                          TextView textView1 = (TextView) findViewById(R.id.textv1);
                          textView1.setAutoLinkMask(Linkify.PHONE_NUMBERS);
                          textView1.setText("852112222");

                          // Tested OK!
                          TextView textView2 = (TextView) findViewById(R.id.textv2);
                          textView2.setAutoLinkMask(Linkify.PHONE_NUMBERS);
                          textView2.setText("(85) 211-2222");

                          // Tested Failed!
                          // Reason : Need to apply setAutoLinkMask prior to apply setText
                          TextView textView3 = (TextView) findViewById(R.id.textv3);
                          textView3.setText("852112222");
                          textView2.setAutoLinkMask(Linkify.PHONE_NUMBERS);

                          }
                          }


                          View



                          <?xml version="1.0" encoding="utf-8"?>
                          <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
                          android:id="@+id/activity_main"
                          android:layout_width="match_parent"
                          android:layout_height="match_parent"
                          android:orientation="vertical">

                          <TextView
                          android:id="@+id/textv1"
                          android:layout_width="match_parent"
                          android:layout_height="wrap_content" />

                          <TextView
                          android:id="@+id/textv2"
                          android:layout_width="match_parent"
                          android:layout_height="wrap_content" />

                          <TextView
                          android:id="@+id/textv3"
                          android:layout_width="match_parent"
                          android:layout_height="55dp" />

                          </LinearLayout>


                          enter image description here



                          Testing Devices




                          1. One plus one with Android 7.1

                          2. Genymotion. 4.1.1 - API 16







                          share|improve this answer














                          share|improve this answer



                          share|improve this answer








                          edited Nov 29 '16 at 9:58

























                          answered Nov 26 '16 at 15:48









                          youngyoung

                          1,33621126




                          1,33621126













                          • Still same result. On some devices same number is linkified on other it does not. And it doesn't matter if I use Linkify.PHONE_NUMBERS or Linkify.ALL

                            – Martynas Jurkus
                            Nov 28 '16 at 10:19











                          • Everything seems working fine here. Let me know your feedback.

                            – young
                            Nov 29 '16 at 10:01











                          • Took your sample code - no luck. imgur.com/cSLuOdt Used same devices, even other SDK versions. Same result.

                            – Martynas Jurkus
                            Nov 29 '16 at 11:41













                          • @MartynasJurkus Your image shown that second one was partially linkified

                            – young
                            Nov 29 '16 at 11:45













                          • okay! will check one more time and let me know if you fix this.

                            – young
                            Nov 29 '16 at 11:51



















                          • Still same result. On some devices same number is linkified on other it does not. And it doesn't matter if I use Linkify.PHONE_NUMBERS or Linkify.ALL

                            – Martynas Jurkus
                            Nov 28 '16 at 10:19











                          • Everything seems working fine here. Let me know your feedback.

                            – young
                            Nov 29 '16 at 10:01











                          • Took your sample code - no luck. imgur.com/cSLuOdt Used same devices, even other SDK versions. Same result.

                            – Martynas Jurkus
                            Nov 29 '16 at 11:41













                          • @MartynasJurkus Your image shown that second one was partially linkified

                            – young
                            Nov 29 '16 at 11:45













                          • okay! will check one more time and let me know if you fix this.

                            – young
                            Nov 29 '16 at 11:51

















                          Still same result. On some devices same number is linkified on other it does not. And it doesn't matter if I use Linkify.PHONE_NUMBERS or Linkify.ALL

                          – Martynas Jurkus
                          Nov 28 '16 at 10:19





                          Still same result. On some devices same number is linkified on other it does not. And it doesn't matter if I use Linkify.PHONE_NUMBERS or Linkify.ALL

                          – Martynas Jurkus
                          Nov 28 '16 at 10:19













                          Everything seems working fine here. Let me know your feedback.

                          – young
                          Nov 29 '16 at 10:01





                          Everything seems working fine here. Let me know your feedback.

                          – young
                          Nov 29 '16 at 10:01













                          Took your sample code - no luck. imgur.com/cSLuOdt Used same devices, even other SDK versions. Same result.

                          – Martynas Jurkus
                          Nov 29 '16 at 11:41







                          Took your sample code - no luck. imgur.com/cSLuOdt Used same devices, even other SDK versions. Same result.

                          – Martynas Jurkus
                          Nov 29 '16 at 11:41















                          @MartynasJurkus Your image shown that second one was partially linkified

                          – young
                          Nov 29 '16 at 11:45







                          @MartynasJurkus Your image shown that second one was partially linkified

                          – young
                          Nov 29 '16 at 11:45















                          okay! will check one more time and let me know if you fix this.

                          – young
                          Nov 29 '16 at 11:51





                          okay! will check one more time and let me know if you fix this.

                          – young
                          Nov 29 '16 at 11:51











                          5














                          Just do the following



                          TextView userInput= (TextView) view.findViewById(R.id.textView);

                          if(userInput != null){
                          Linkify.addLinks(userInput, Patterns.PHONE,"tel:",Linkify.sPhoneNumberMatchFilter,Linkify.sPhoneNumberTransformFilter);
                          userInput.setMovementMethod(LinkMovementMethod.getInstance());
                          }


                          and also remove the



                          android:autoLink


                          from your xml file






                          share|improve this answer




























                            5














                            Just do the following



                            TextView userInput= (TextView) view.findViewById(R.id.textView);

                            if(userInput != null){
                            Linkify.addLinks(userInput, Patterns.PHONE,"tel:",Linkify.sPhoneNumberMatchFilter,Linkify.sPhoneNumberTransformFilter);
                            userInput.setMovementMethod(LinkMovementMethod.getInstance());
                            }


                            and also remove the



                            android:autoLink


                            from your xml file






                            share|improve this answer


























                              5












                              5








                              5







                              Just do the following



                              TextView userInput= (TextView) view.findViewById(R.id.textView);

                              if(userInput != null){
                              Linkify.addLinks(userInput, Patterns.PHONE,"tel:",Linkify.sPhoneNumberMatchFilter,Linkify.sPhoneNumberTransformFilter);
                              userInput.setMovementMethod(LinkMovementMethod.getInstance());
                              }


                              and also remove the



                              android:autoLink


                              from your xml file






                              share|improve this answer













                              Just do the following



                              TextView userInput= (TextView) view.findViewById(R.id.textView);

                              if(userInput != null){
                              Linkify.addLinks(userInput, Patterns.PHONE,"tel:",Linkify.sPhoneNumberMatchFilter,Linkify.sPhoneNumberTransformFilter);
                              userInput.setMovementMethod(LinkMovementMethod.getInstance());
                              }


                              and also remove the



                              android:autoLink


                              from your xml file







                              share|improve this answer












                              share|improve this answer



                              share|improve this answer










                              answered May 25 '18 at 8:24









                              Harsh AgrawalHarsh Agrawal

                              409210




                              409210























                                  4














                                  I have seen a lot of inconsistencies when using auto link. If at all you are working for a prod version. Always go for SpannableStringBuilder with LinkMovementMethod. You have good control of how the text needs to be displayed.



                                  The snippet below may help.



                                  String phone = "your phone number";
                                  String message = "Phone number is: ";

                                  Spannable span = new SpannableString(String.format("%sn%s",message, phone));
                                  ForegroundColorSpan color = new ForegroundColorSpan(Res.color(R.color.blue));
                                  ClickableSpan click = new ClickableSpan() {
                                  @Override
                                  public void onClick(View widget) {
                                  Navigator.dialer("your phone number");
                                  }
                                  public void updateDrawState(TextPaint ds) {// override updateDrawState
                                  ds.setUnderlineText(false); // set to false to remove underline
                                  }
                                  };

                                  span.setSpan(color, message.length(), message.length() + phone.length() + 1, Spanned.SPAN_INCLUSIVE_INCLUSIVE);
                                  span.setSpan(click, message.length(), message.length() + phone.length() + 1, Spanned.SPAN_INCLUSIVE_INCLUSIVE);

                                  changesMessageLabel.setText(span);
                                  changesMessageLabel.setMovementMethod(LinkMovementMethod.getInstance());





                                  share|improve this answer




























                                    4














                                    I have seen a lot of inconsistencies when using auto link. If at all you are working for a prod version. Always go for SpannableStringBuilder with LinkMovementMethod. You have good control of how the text needs to be displayed.



                                    The snippet below may help.



                                    String phone = "your phone number";
                                    String message = "Phone number is: ";

                                    Spannable span = new SpannableString(String.format("%sn%s",message, phone));
                                    ForegroundColorSpan color = new ForegroundColorSpan(Res.color(R.color.blue));
                                    ClickableSpan click = new ClickableSpan() {
                                    @Override
                                    public void onClick(View widget) {
                                    Navigator.dialer("your phone number");
                                    }
                                    public void updateDrawState(TextPaint ds) {// override updateDrawState
                                    ds.setUnderlineText(false); // set to false to remove underline
                                    }
                                    };

                                    span.setSpan(color, message.length(), message.length() + phone.length() + 1, Spanned.SPAN_INCLUSIVE_INCLUSIVE);
                                    span.setSpan(click, message.length(), message.length() + phone.length() + 1, Spanned.SPAN_INCLUSIVE_INCLUSIVE);

                                    changesMessageLabel.setText(span);
                                    changesMessageLabel.setMovementMethod(LinkMovementMethod.getInstance());





                                    share|improve this answer


























                                      4












                                      4








                                      4







                                      I have seen a lot of inconsistencies when using auto link. If at all you are working for a prod version. Always go for SpannableStringBuilder with LinkMovementMethod. You have good control of how the text needs to be displayed.



                                      The snippet below may help.



                                      String phone = "your phone number";
                                      String message = "Phone number is: ";

                                      Spannable span = new SpannableString(String.format("%sn%s",message, phone));
                                      ForegroundColorSpan color = new ForegroundColorSpan(Res.color(R.color.blue));
                                      ClickableSpan click = new ClickableSpan() {
                                      @Override
                                      public void onClick(View widget) {
                                      Navigator.dialer("your phone number");
                                      }
                                      public void updateDrawState(TextPaint ds) {// override updateDrawState
                                      ds.setUnderlineText(false); // set to false to remove underline
                                      }
                                      };

                                      span.setSpan(color, message.length(), message.length() + phone.length() + 1, Spanned.SPAN_INCLUSIVE_INCLUSIVE);
                                      span.setSpan(click, message.length(), message.length() + phone.length() + 1, Spanned.SPAN_INCLUSIVE_INCLUSIVE);

                                      changesMessageLabel.setText(span);
                                      changesMessageLabel.setMovementMethod(LinkMovementMethod.getInstance());





                                      share|improve this answer













                                      I have seen a lot of inconsistencies when using auto link. If at all you are working for a prod version. Always go for SpannableStringBuilder with LinkMovementMethod. You have good control of how the text needs to be displayed.



                                      The snippet below may help.



                                      String phone = "your phone number";
                                      String message = "Phone number is: ";

                                      Spannable span = new SpannableString(String.format("%sn%s",message, phone));
                                      ForegroundColorSpan color = new ForegroundColorSpan(Res.color(R.color.blue));
                                      ClickableSpan click = new ClickableSpan() {
                                      @Override
                                      public void onClick(View widget) {
                                      Navigator.dialer("your phone number");
                                      }
                                      public void updateDrawState(TextPaint ds) {// override updateDrawState
                                      ds.setUnderlineText(false); // set to false to remove underline
                                      }
                                      };

                                      span.setSpan(color, message.length(), message.length() + phone.length() + 1, Spanned.SPAN_INCLUSIVE_INCLUSIVE);
                                      span.setSpan(click, message.length(), message.length() + phone.length() + 1, Spanned.SPAN_INCLUSIVE_INCLUSIVE);

                                      changesMessageLabel.setText(span);
                                      changesMessageLabel.setMovementMethod(LinkMovementMethod.getInstance());






                                      share|improve this answer












                                      share|improve this answer



                                      share|improve this answer










                                      answered Dec 2 '16 at 17:27









                                      CleverAndroidCleverAndroid

                                      413




                                      413























                                          4














                                          I would suggest you just to add country code and all your issue will be resolved,



                                          android:autoLink="phone"
                                          android:text="+91-8000000000"


                                          If we add country code before the number, then no need of other temporary solutions.






                                          share|improve this answer
























                                          • That would work. Although phone numbers is user input and it is not common practice to enter country codes when entering same country phone number so I can't force validation on them.

                                            – Martynas Jurkus
                                            Feb 26 '18 at 7:57











                                          • Adding Country Code will help developer to resolve, future issues when his/her Android App is used globally. In that case, user will not be able to make a call due to no country code (Invalid number). So, why not add it beforehand to resolve future issues, and this approach will even help developer from adding other temporary solutions to make android:autoLink work.

                                            – miPlodder
                                            Feb 27 '18 at 7:03








                                          • 1





                                            Just to confirm, this worked for me

                                            – Ivan Milisavljevic
                                            Nov 11 '18 at 19:24
















                                          4














                                          I would suggest you just to add country code and all your issue will be resolved,



                                          android:autoLink="phone"
                                          android:text="+91-8000000000"


                                          If we add country code before the number, then no need of other temporary solutions.






                                          share|improve this answer
























                                          • That would work. Although phone numbers is user input and it is not common practice to enter country codes when entering same country phone number so I can't force validation on them.

                                            – Martynas Jurkus
                                            Feb 26 '18 at 7:57











                                          • Adding Country Code will help developer to resolve, future issues when his/her Android App is used globally. In that case, user will not be able to make a call due to no country code (Invalid number). So, why not add it beforehand to resolve future issues, and this approach will even help developer from adding other temporary solutions to make android:autoLink work.

                                            – miPlodder
                                            Feb 27 '18 at 7:03








                                          • 1





                                            Just to confirm, this worked for me

                                            – Ivan Milisavljevic
                                            Nov 11 '18 at 19:24














                                          4












                                          4








                                          4







                                          I would suggest you just to add country code and all your issue will be resolved,



                                          android:autoLink="phone"
                                          android:text="+91-8000000000"


                                          If we add country code before the number, then no need of other temporary solutions.






                                          share|improve this answer













                                          I would suggest you just to add country code and all your issue will be resolved,



                                          android:autoLink="phone"
                                          android:text="+91-8000000000"


                                          If we add country code before the number, then no need of other temporary solutions.







                                          share|improve this answer












                                          share|improve this answer



                                          share|improve this answer










                                          answered Feb 25 '18 at 21:04









                                          miPloddermiPlodder

                                          7710




                                          7710













                                          • That would work. Although phone numbers is user input and it is not common practice to enter country codes when entering same country phone number so I can't force validation on them.

                                            – Martynas Jurkus
                                            Feb 26 '18 at 7:57











                                          • Adding Country Code will help developer to resolve, future issues when his/her Android App is used globally. In that case, user will not be able to make a call due to no country code (Invalid number). So, why not add it beforehand to resolve future issues, and this approach will even help developer from adding other temporary solutions to make android:autoLink work.

                                            – miPlodder
                                            Feb 27 '18 at 7:03








                                          • 1





                                            Just to confirm, this worked for me

                                            – Ivan Milisavljevic
                                            Nov 11 '18 at 19:24



















                                          • That would work. Although phone numbers is user input and it is not common practice to enter country codes when entering same country phone number so I can't force validation on them.

                                            – Martynas Jurkus
                                            Feb 26 '18 at 7:57











                                          • Adding Country Code will help developer to resolve, future issues when his/her Android App is used globally. In that case, user will not be able to make a call due to no country code (Invalid number). So, why not add it beforehand to resolve future issues, and this approach will even help developer from adding other temporary solutions to make android:autoLink work.

                                            – miPlodder
                                            Feb 27 '18 at 7:03








                                          • 1





                                            Just to confirm, this worked for me

                                            – Ivan Milisavljevic
                                            Nov 11 '18 at 19:24

















                                          That would work. Although phone numbers is user input and it is not common practice to enter country codes when entering same country phone number so I can't force validation on them.

                                          – Martynas Jurkus
                                          Feb 26 '18 at 7:57





                                          That would work. Although phone numbers is user input and it is not common practice to enter country codes when entering same country phone number so I can't force validation on them.

                                          – Martynas Jurkus
                                          Feb 26 '18 at 7:57













                                          Adding Country Code will help developer to resolve, future issues when his/her Android App is used globally. In that case, user will not be able to make a call due to no country code (Invalid number). So, why not add it beforehand to resolve future issues, and this approach will even help developer from adding other temporary solutions to make android:autoLink work.

                                          – miPlodder
                                          Feb 27 '18 at 7:03







                                          Adding Country Code will help developer to resolve, future issues when his/her Android App is used globally. In that case, user will not be able to make a call due to no country code (Invalid number). So, why not add it beforehand to resolve future issues, and this approach will even help developer from adding other temporary solutions to make android:autoLink work.

                                          – miPlodder
                                          Feb 27 '18 at 7:03






                                          1




                                          1





                                          Just to confirm, this worked for me

                                          – Ivan Milisavljevic
                                          Nov 11 '18 at 19:24





                                          Just to confirm, this worked for me

                                          – Ivan Milisavljevic
                                          Nov 11 '18 at 19:24











                                          1














                                          For phone autolink specific you should use



                                          android:autoLink="phone"


                                          For more refer: textview autolink






                                          share|improve this answer
























                                          • Why? android:autoLink="phone" should work too. And it works on some devices. And that wasn't the question.

                                            – Martynas Jurkus
                                            Nov 24 '16 at 15:59


















                                          1














                                          For phone autolink specific you should use



                                          android:autoLink="phone"


                                          For more refer: textview autolink






                                          share|improve this answer
























                                          • Why? android:autoLink="phone" should work too. And it works on some devices. And that wasn't the question.

                                            – Martynas Jurkus
                                            Nov 24 '16 at 15:59
















                                          1












                                          1








                                          1







                                          For phone autolink specific you should use



                                          android:autoLink="phone"


                                          For more refer: textview autolink






                                          share|improve this answer













                                          For phone autolink specific you should use



                                          android:autoLink="phone"


                                          For more refer: textview autolink







                                          share|improve this answer












                                          share|improve this answer



                                          share|improve this answer










                                          answered Nov 24 '16 at 14:31









                                          Ready AndroidReady Android

                                          1,9351227




                                          1,9351227













                                          • Why? android:autoLink="phone" should work too. And it works on some devices. And that wasn't the question.

                                            – Martynas Jurkus
                                            Nov 24 '16 at 15:59





















                                          • Why? android:autoLink="phone" should work too. And it works on some devices. And that wasn't the question.

                                            – Martynas Jurkus
                                            Nov 24 '16 at 15:59



















                                          Why? android:autoLink="phone" should work too. And it works on some devices. And that wasn't the question.

                                          – Martynas Jurkus
                                          Nov 24 '16 at 15:59







                                          Why? android:autoLink="phone" should work too. And it works on some devices. And that wasn't the question.

                                          – Martynas Jurkus
                                          Nov 24 '16 at 15:59













                                          1














                                          Harsh Agrawal answer worked for me in cases where the phone number is 11 digits or more with 3 blocks. e.g. 123 456 78910



                                          TextView textView = findViewById(R.id.text_view);
                                          textView.setText("123 456 78910");
                                          Linkify.addLinks(textView, Patterns.PHONE, "tel:", Linkify.sPhoneNumberMatchFilter,
                                          Linkify.sPhoneNumberTransformFilter);


                                          I had to call Linkify.addLinks after setting text for it to work.



                                          Note that Linkify.addLinks already calls setMovementMethod on the text view.






                                          share|improve this answer




























                                            1














                                            Harsh Agrawal answer worked for me in cases where the phone number is 11 digits or more with 3 blocks. e.g. 123 456 78910



                                            TextView textView = findViewById(R.id.text_view);
                                            textView.setText("123 456 78910");
                                            Linkify.addLinks(textView, Patterns.PHONE, "tel:", Linkify.sPhoneNumberMatchFilter,
                                            Linkify.sPhoneNumberTransformFilter);


                                            I had to call Linkify.addLinks after setting text for it to work.



                                            Note that Linkify.addLinks already calls setMovementMethod on the text view.






                                            share|improve this answer


























                                              1












                                              1








                                              1







                                              Harsh Agrawal answer worked for me in cases where the phone number is 11 digits or more with 3 blocks. e.g. 123 456 78910



                                              TextView textView = findViewById(R.id.text_view);
                                              textView.setText("123 456 78910");
                                              Linkify.addLinks(textView, Patterns.PHONE, "tel:", Linkify.sPhoneNumberMatchFilter,
                                              Linkify.sPhoneNumberTransformFilter);


                                              I had to call Linkify.addLinks after setting text for it to work.



                                              Note that Linkify.addLinks already calls setMovementMethod on the text view.






                                              share|improve this answer













                                              Harsh Agrawal answer worked for me in cases where the phone number is 11 digits or more with 3 blocks. e.g. 123 456 78910



                                              TextView textView = findViewById(R.id.text_view);
                                              textView.setText("123 456 78910");
                                              Linkify.addLinks(textView, Patterns.PHONE, "tel:", Linkify.sPhoneNumberMatchFilter,
                                              Linkify.sPhoneNumberTransformFilter);


                                              I had to call Linkify.addLinks after setting text for it to work.



                                              Note that Linkify.addLinks already calls setMovementMethod on the text view.







                                              share|improve this answer












                                              share|improve this answer



                                              share|improve this answer










                                              answered Nov 21 '18 at 23:36









                                              fluxeonfluxeon

                                              111




                                              111






























                                                  draft saved

                                                  draft discarded




















































                                                  Thanks for contributing an answer to Stack Overflow!


                                                  • Please be sure to answer the question. Provide details and share your research!

                                                  But avoid



                                                  • Asking for help, clarification, or responding to other answers.

                                                  • Making statements based on opinion; back them up with references or personal experience.


                                                  To learn more, see our tips on writing great answers.




                                                  draft saved


                                                  draft discarded














                                                  StackExchange.ready(
                                                  function () {
                                                  StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f40788608%2fandroidautolink-for-phone-numbers-doesnt-always-work%23new-answer', 'question_page');
                                                  }
                                                  );

                                                  Post as a guest















                                                  Required, but never shown





















































                                                  Required, but never shown














                                                  Required, but never shown












                                                  Required, but never shown







                                                  Required, but never shown

































                                                  Required, but never shown














                                                  Required, but never shown












                                                  Required, but never shown







                                                  Required, but never shown







                                                  Popular posts from this blog

                                                  MongoDB - Not Authorized To Execute Command

                                                  How to fix TextFormField cause rebuild widget in Flutter

                                                  Npm cannot find a required file even through it is in the searched directory