Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

make a phone call click on a button

I'm trying to make a call when I press a button in android

((Button)findViewById(R.id.button1)).setOnClickListener(new OnClickListener() {   @Override   public void onClick(View v) {     String phno="10digits";      Intent i=new Intent(Intent.ACTION_DIAL,Uri.parse(phno));     startActivity(i);   } }); 

But when I run and click on the button it gives me the error

ERROR/AndroidRuntime(1021): android.content.ActivityNotFoundException: No Activity found to handle Intent { act=android.intent.action.CALL dat=9392438004 } 

How can I resolve this problem?

like image 623
prasad.gai Avatar asked Mar 23 '11 09:03

prasad.gai


People also ask

How do I make a phone number clickable?

Href=tel: creates the call link. This tells the browser how to use the number. “Tel: 123-456-7890 “creates the HTML phone number. The number within the quotes is the number it will call.

What is a click-to-call button?

Click-to-call buttons are exactly as they sound. You provide website visitors with your phone number via a clickable link. If a prospect or customer clicks on the link, it immediately starts dialing.

How do you trigger a phone call when clicking a link in a Web page on your phone?

Most modern devices support the tel: scheme. So use <a href="tel:555-555-5555">555-555-5555</a> and you should be good to go.


2 Answers

Have you given the permission in the manifest file

 <uses-permission android:name="android.permission.CALL_PHONE"></uses-permission>    

and inside your activity

  Intent callIntent = new Intent(Intent.ACTION_CALL);     callIntent.setData(Uri.parse("tel:123456789"));     startActivity(callIntent); 

Let me know if you find any issue.

like image 107
Shaista Naaz Avatar answered Oct 05 '22 01:10

Shaista Naaz


There are two intents to call/start calling: ACTION_CALL and ACTION_DIAL.

ACTION_DIAL will only open the dialer with the number filled in, but allows the user to actually call or reject the call. ACTION_CALL will immediately call the number and requires an extra permission.

So make sure you have the permission

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

in your AndroidManifest.xml

<manifest     xmlns:android="http://schemas.android.com/apk/res/android"     package="com.dbm.pkg"     android:versionCode="1"     android:versionName="1.0">      <!-- NOTE! Your uses-permission must be outside the "application" tag                but within the "manifest" tag. -->      <uses-permission android:name="android.permission.CALL_PHONE" />      <application         android:icon="@drawable/icon"         android:label="@string/app_name">          <!-- Insert your other stuff here -->      </application>      <uses-sdk android:minSdkVersion="9" /> </manifest>  
like image 29
Zar E Ahmer Avatar answered Oct 05 '22 00:10

Zar E Ahmer