Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ActivityNotFoundException when calling Intent.ACTION_CALL

I get ActivityNotFoundException when perform Intent.ACTION_CALL operation. I found many links but all of it couldn't solve my problem.

It sometimes gives me exception like

android.content.ActivityNotFoundException: No Activity found to handle Intent { act=android.intent.action.CALL dat=tel:xxx-xxx-xxxx pkg=com.android.phone (has extras) }

I have used the following code in my project

String contact_number="123456789";
Intent callIntent = new Intent(Intent.ACTION_CALL);
callIntent.setData(Uri.parse("tel:" + contact_number));
startActivity(callIntent);
like image 239
Nooruddin Lakhani Avatar asked Jan 26 '15 08:01

Nooruddin Lakhani


2 Answers

I have solved this issue. I have used the following code

String contact_number="123456789";
Intent callIntent = new Intent(Intent.ACTION_CALL);
intent.setPackage("com.android.phone");
callIntent.setData(Uri.parse("tel:" + contact_number));
startActivity(callIntent);

I have replaced this line for Lollipop

intent.setPackage("com.android.phone");

with

intent.setPackage("com.android.server.telecom");
like image 158
Nooruddin Lakhani Avatar answered Nov 15 '22 11:11

Nooruddin Lakhani


You should check if there are any activities that handle this intent before starting it. This can happen if your app run on a tablet with wifi only and has no phone capability. Also if you only intend to launch dialer, better use ACTION_DIAL than ACTION_CALL which makes the call directly from your app.

final Intent dialIntent = new Intent(Intent.ACTION_DIAL, Uri.parse("tel:"));
if (dialIntent.resolveActivity(context.getPackageManager()) != null) {
    // put your logic to launch call app here
  }
like image 34
hidro Avatar answered Nov 15 '22 13:11

hidro