1

in android,

I want to make the text in that there is a number in that when I click on the number the call will be automatically done.means call window should open when I click on the number

here you can see that there is bold text with plain text and also there is a number which is highlighted when I click on that number it will bring up call activity

for example below is the imageenter image description here

here you can see that there is bold text with plain text and also there is a number which is highlighted when I click on that number it will bring up call activity

madhan kumar
  • 1,560
  • 2
  • 26
  • 36
Komal Sorathiya
  • 228
  • 1
  • 9

2 Answers2

2

you can do this by below code, it successfully working

public class MainActivity extends Activity {

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    WebView webView = (WebView)findViewById(R.id.webView);
    webView.loadData("<html>Please use the form below to request a specific day and time for your pet’s appointment.<br> <b>Please Note: </b> For same day appointment requests, please call: (215) 884-0453<a href=\"tel:2125551212\">2125551212</a></html>", "text/html", "utf-8");
    webView.setWebViewClient(new InternalWebViewClient());
}

private class InternalWebViewClient extends WebViewClient {

    @Override
    public boolean shouldOverrideUrlLoading(WebView view, String url) {
         if (url.indexOf("tel:") > -1) {
            startActivity(new Intent(Intent.ACTION_DIAL, Uri.parse(url)));
            return true;
        } else {
            return true;
        }
    }
}

}
Siddhpura Amit
  • 14,534
  • 16
  • 91
  • 150
0

Use webView for that. All things you require will be done automatically by webView in itself. This will help you with calling / Map view / Url opening functionality at one time with out any concern for defining static values with in your code .

If you are getting some string value with or without some html tag then you can use undermentioned :

WebView wv = (WebView)rootView.findViewById(R.id.go_web_view);
        wv.getSettings().setJavaScriptEnabled(true);
        wv.loadDataWithBaseURL(null, description, "text/html", "utf-8", null);

// Here "description" is your string 

You xml file

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/hsf"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical"
    android:background="@color/white"
     >
 <include layout="@layout/header"/>
   <ScrollView 
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        >

    <LinearLayout
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:orientation="vertical" >

   <ImageView
        android:id="@+id/go_large"
        android:layout_width="360dp"
        android:layout_height="195dp"
        android:src="@drawable/image_not_available"
        android:gravity="center" />

    <TextView
        android:layout_marginTop="20dp"
        android:id="@+id/go_excert"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:textSize="20sp"
        android:textStyle="bold"  
        android:layout_marginLeft="6dp"      
        />

    <LinearLayout
        android:layout_marginTop="15dp"
        android:layout_marginBottom="15dp"
        android:layout_width="match_parent"
        android:layout_height="2dp"
        android:layout_marginLeft="4dp"
        android:layout_marginRight="4dp"
        android:background="@color/grey" >
    </LinearLayout>



    <WebView
        android:id="@+id/go_web_view"
        android:layout_width="match_parent"
        android:layout_height="wrap_content" />

    </LinearLayout>

    </ScrollView>



</LinearLayout>

Cheers !

AndroidHacker
  • 3,596
  • 1
  • 25
  • 45