Suroj
Suroj

Reputation: 2265

Call Number from Android App from Native calling app programatically

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?

Upvotes: 9

Views: 2500

Answers (3)

jobbert
jobbert

Reputation: 3497

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); 

Upvotes: 0

Rajesh Jadav
Rajesh Jadav

Reputation: 12861

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!

Upvotes: 11

Androider
Androider

Reputation: 3873

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" />

Upvotes: 1

Related Questions