9

I use followoing permission to make phone call from my application

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

Here is my code for making call.

 Intent iniCall=new Intent(Intent.ACTION_CALL);
 iniCall.setData(Uri.parse("tel:9849199291");
 startActivity(iniCall);   

But It start the Skype Application instead of starting Default Calling Application.

How to call from default calling application?

Rajesh Jadav
  • 12,801
  • 5
  • 53
  • 78
Suroj
  • 2,127
  • 1
  • 12
  • 14
  • 1
    possible duplicate of [how to make phone call using intent in android?](http://stackoverflow.com/questions/4275678/how-to-make-phone-call-using-intent-in-android) – Viktor Yakunin Sep 02 '15 at 11:42
  • 2
    it starts the skype app because it is the app the user has chosen to be the **default app** to handle the calling action. – njzk2 Sep 02 '15 at 12:14

3 Answers3

11

For Pre-Lollipop devices you need to use com.android.phone as package name and in Lollipop you need to use com.android.server.telecom as package name.

Try this code:

Intent iniCall=new Intent(Intent.ACTION_CALL);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
   iniCall.setPackage("com.android.server.telecom"); 
}else{
   iniCall.setPackage("com.android.phone"); 
} 
iniCall.setData(Uri.parse("tel:"+9849199291);
startActivity(iniCall); 

I hope it helps!

Rajesh Jadav
  • 12,801
  • 5
  • 53
  • 78
1

mainactivity code:

  button.setOnClickListener(new OnClickListener() {

    @Override
   public void onClick(View arg0) {
    String phnum = edittext.getText().toString();
    Intent callIntent = new Intent(Intent.ACTION_CALL);
    callIntent.setData(Uri.parse("tel:" + phnum));
    startActivity(callIntent);
   }
  });

manifest:

<uses-permission android:name="android.permission.CALL_PHONE" />
Androider
  • 3,833
  • 2
  • 14
  • 24
0

I personally prefer the method that doesn't require a permission, but does require the user to press dial in the dialpad like this:

Uri uri = Uri.parse("tel:" + number);
Intent callIntent = new Intent(Intent.ACTION_DIAL, uri);
context.startActivity(callIntent); 
jobbert
  • 3,297
  • 27
  • 43