Suroj Suroj - 25 days ago 12
Android Question

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?

Answer

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!

Comments