-1

1) I have used linkify html method link

 value = "<a href="+to_tel+">"+number+"</a>";
 Linkify.addLinks(t, Linkify.PHONE_NUMBERS);
 Html.fromHtml(value);`                

2) Clickable Span method

ClickableSpan clickableSpan = new ClickableSpan() {
     @Override
     public void onClick(View textView) {
        Intent intent = new Intent(Intent.ACTION_DIAL);
        intent.setData(Uri.parse("tel:" + phoneNumber.replace(" ", "")));
        startActivity(intent); 
 }


SpannableString spannableString = new SpannableString(stringBuilder);
spannableString.setSpan(clickableSpan, phoneSpanStart, phoneSpanEnd,Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
Rahul Khurana
  • 8,577
  • 7
  • 33
  • 60

1 Answers1

1

The second approach is best which is using the intent. As it is officially recommended in Android documentation.

Intent intent = new Intent(Intent.ACTION_DIAL);
intent.setData(Uri.parse("tel:" + phoneNumber.replace(" ", "")));
startActivity(intent); 

Note:

Places a phone call (requires the CALL_PHONE permission)

<uses-permission android:name="android.permission.CALL_PHONE" />
Rahul Khurana
  • 8,577
  • 7
  • 33
  • 60