How to make a phone call on clicking a button in android
- March 26, 2016
- Android App Development
In some of the apps that we develop we may need to make a call through it. This could easily be done by using implicit Intent with appropriate actions.We can use Android Intent to make phone call by calling built-in Phone Call functionality of the Android.In my code i will be using ACTION_DIAL where we will be having option to modify hard coded phone number before making a call instead of making direct call.
Intent callIntent = new Intent(Intent.ACTION_DIAL, number);
Following code snippet shows how to use Android Intent to make phone call to the given mobile number.
protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); Button callbutton = (Button) findViewById(R.id.callbtn); callbutton.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { Uri number = Uri.parse("tel:0123456789"); Intent callIntent = new Intent(Intent.ACTION_DIAL, number); startActivity(callIntent); } }); } We need to add the following button code in xml: <Button android:id="@+id/callbtn" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_marginLeft="50dp" android:layout_marginTop="130dp" android:text="0123456789" />
About us and this blog
We are a digital marketing company with a focus on helping our customers achieve great results across several key areas.
Request a free quote
We offer professional SEO services that help websites increase their organic search score drastically in order to compete for the highest rankings even when it comes to highly competitive keywords.
Subscribe to our newsletter!
More from our blog
See all postsRecent Posts
- Top 5 Marketing Channels: Examples With Pros & Cons February 23, 2023
- The 8-Step Checklist for Launching an influencer Marketing February 23, 2023
- How to Build an Email List Through Social Media January 31, 2023