54

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?

Vadim Kotov
  • 8,084
  • 8
  • 48
  • 62
prasad.gai
  • 2,977
  • 10
  • 58
  • 93

14 Answers14

146

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.

Shaista Naaz
  • 8,281
  • 9
  • 37
  • 50
  • 2
    There is absolutely no issues at all. Wow!!! I am just learning to write apps for Android now and this question was asked back in 2011. Thank you for this short and sweet answer. – ThN Dec 06 '13 at 19:19
  • 24
    You should not use Intent.ACTION_CALL unless you are writing a dialer app. Instead you should use Intent.ACTION_DIAL which prepopulates the dialer with the number you pass it. The proper fix for the problem is to just prepend "tel:" in front of the 10 digits number you want to call. – David Shellabarger Dec 11 '13 at 02:07
  • **10 digits**? so you can't call a mobile with international prefix, like +491702112334? because this is **13 digits** – Phantômaxx Dec 14 '13 at 09:45
  • I know this is old but im doing stuff for old hardware. Im getting the "No Activity Found" exception on the android 2,1 (api 7) platform. Is there a way to dial from this platform? – Justin Oct 02 '15 at 07:28
  • No need to add permission when using ACTION_DIAL – gonephishing Sep 27 '17 at 21:52
16

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> 
Zar E Ahmer
  • 33,936
  • 20
  • 234
  • 300
  • hi,i have a question regarding this answer.If i have to make call to an international phone number,then where should i mention the country code? – Nevaeh Apr 07 '15 at 09:02
  • I don't have access to this code anymore. Sorry but it may help http://stackoverflow.com/questions/13132724/checking-if-call-being-made-is-international – Zar E Ahmer Apr 07 '15 at 10:16
13

None of the above worked so with a bit of tinkering here's code that did for me

        Intent i = new Intent(Intent.ACTION_DIAL);
        String p = "tel:" + getString(R.string.phone_number);
        i.setData(Uri.parse(p));
        startActivity(i);
kenwen
  • 814
  • 2
  • 11
  • 17
12

change your String to String phno="tel:10digits"; and try again.

prasad.gai
  • 2,977
  • 10
  • 58
  • 93
Harshad
  • 7,904
  • 3
  • 24
  • 42
  • thanks Harshad but i can't get any key pad it can directly call to that number without user modification of that number – prasad.gai Mar 23 '11 at 10:28
  • You want to call directly without showing dial pad??? if so then use `Intent i = new Intent(Intent.ACTION_CALL, Uri.parse(phno));` – Harshad Mar 23 '11 at 10:30
  • Calling directly as above will not work unless and untill you add this line as child of your manifest in manifest file `` – Harshad Mar 23 '11 at 10:35
  • did this think worked? You can accept the answer and help others if it is correct.. – Harshad Mar 23 '11 at 12:13
  • how directly make a video call to particular phone no provided in tel:10digit no,duo video call from android pleae help me. – Harsha Feb 06 '18 at 06:40
8

I was having a hell of a time with this as well. I didn't realize that beyond the extra permission you need to append "tel:" onto the string that has the number in it. This is what mine looks like after getting it functional. Hope this helps.

@Override
public void onClick(View v) {
  Intent intent = new Intent(Intent.ACTION_DIAL);
  String temp = "tel:" + phone;
  intent.setData(Uri.parse(temp));

  startActivity(intent);
}
JCrooks
  • 113
  • 1
  • 6
5

check permissions before (for android 6 and above):

if (ActivityCompat.checkSelfPermission(context, Manifest.permission.CALL_PHONE) ==
                            PackageManager.PERMISSION_GRANTED) 
   {

     context.startActivity(new Intent(Intent.ACTION_CALL, Uri.parse("tel:09130000000")));
   }
javad
  • 833
  • 14
  • 37
4

add "tel:" along with your number to be dialed in your intent and then start your activity.

Intent myIntent = new Intent(Intent.ACTION_CALL);
 String phNum = "tel:" + "1234567890";
 myIntent.setData(Uri.parse(phNum));
  startActivity( myIntent ) ;
Ashu Singh
  • 341
  • 4
  • 7
4

To have the code within one line, try this:

startActivity(new Intent(Intent.ACTION_CALL, Uri.parse("tel:123456789")));

along with the proper manifest permission:

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

Hope this helps!

Brian
  • 2,494
  • 1
  • 16
  • 21
2

For those using AppCompact...Try this

import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.content.Intent;
import android.util.Log;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;
import android.net.Uri;

public class MainActivity extends AppCompatActivity {



    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        Button startBtn = (Button) findViewById(R.id.db);
        startBtn.setOnClickListener(new View.OnClickListener() {
            public void onClick(View view) {
                makeCall();
            }
        });

    }

    protected void makeCall() {
        EditText num = (EditText)findViewById(R.id.Dail);
        String phone = num.getText().toString();
        String d = "tel:" + phone ;
        Log.i("Make call", "");
        Intent phoneIntent = new Intent(Intent.ACTION_CALL);
        phoneIntent.setData(Uri.parse(d));
        try {
            startActivity(phoneIntent);
            finish();
            Log.i("Finished making a call", "");
        } catch (android.content.ActivityNotFoundException ex) {
            Toast.makeText(this, "Call faild, please try again later.", Toast.LENGTH_SHORT).show();
        }
    }

}

Then add this to your manifest,,,

 <uses-permission android:name="android.permission.CALL_PHONE" />
X-Black...
  • 1,376
  • 2
  • 20
  • 28
1

Also good to check is telephony supported on device

private boolean isTelephonyEnabled(){
TelephonyManager tm = (TelephonyManager)getSystemService(TELEPHONY_SERVICE);
return tm != null && tm.getSimState()==TelephonyManager.SIM_STATE_READY
}
Aristo Michael
  • 2,166
  • 3
  • 35
  • 43
1
I hope, this short code is useful for You,
   ## Java Code ##
 startActivity(new Intent(Intent.ACTION_DIAL,Uri.parse("tel:"+txtPhn.getText().toString())));



----------------------------------------------------------------------


Please check Manifest File,(for Uses permission)
## Manifest.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 for Making Call ##
    <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> 
0
Button customercare_call=findViewById(R.id.customercare_call); 
 customercare_call.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            String phone = "Mobile Number";
            Intent intent = new  Intent(Intent.ACTION_DIAL,Uri.fromParts("tel", phone, null));    
            startActivity(intent);
        }
    });
0

I've just solved the problem on an Android 4.0.2 device (GN) and the only version working for this device/version was similar to the first 5-starred with CALL_PHONE permission and the answer:

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

With any other solution i got the ActivityNotFoundException on this device/version. How about the older versions? Would someone give feedback?

BossOss
  • 66
  • 4
-1

With permission:

Intent callIntent = new Intent(Intent.ACTION_CALL);
callIntent.setData(Uri.parse("tel:9875432100"));
if (ActivityCompat.checkSelfPermission(yourActivity.this,android.Manifest.permission.CALL_PHONE) != PackageManager.PERMISSION_GRANTED) {
                if (ActivityCompat.shouldShowRequestPermissionRationale(yourActivity.this,
                        android.Manifest.permission.CALL_PHONE)) {
                } else {
                    ActivityCompat.requestPermissions(yourActivity.this,
                            new String[]{android.Manifest.permission.CALL_PHONE},
                            MY_PERMISSIONS_REQUEST_CALL_PHONE);
                }
            }
startActivity(callIntent);
Santhosh
  • 89
  • 1
  • 3