Home » Android » android – How to display phone call window when click on phone number text

android – How to display phone call window when click on phone number text

Posted by: admin June 15, 2020 Leave a comment

Questions:

Im displaying contact details on a screen. I need to display phone call window to appear when user clicks on phone number in the contact details.

Please let me know How i can do this

Thanks in advance

How to&Answers:

I find answer

<TextView  android:text="888-468-0602"  
    android:autoLink="phone" />

Answer:

use this code

String number = "9423012345";

txt.setTag(number);

txt.setOnClickListener(new View.OnClickListener() {

@Override
public void onClick(View v) {   

Intent callIntent = new Intent(Intent.ACTION_CALL);

callIntent.setData(Uri.parse("tel:"+(String) v.getTag()));

callIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); 

startActivity(callIntent);

}});    

And add this line to your manifest file

uses-permission android:name="android.permission.CALL_PHONE"