Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Call Number from Android App from Native calling app programatically

Tags:

android

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?

like image 345
Suroj Avatar asked Sep 02 '15 11:09

Suroj


2 Answers

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!

like image 58
Rajesh Avatar answered Nov 06 '22 19:11

Rajesh


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" />
like image 24
Androider Avatar answered Nov 06 '22 17:11

Androider