Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android Device phone call ability

How can I tell whether a given device has the ability to make phone calls?

For example, my Galaxy Tablet cannot initiate call, its not a phone. I want to detect that before doing a call to isIntentAvailable(context, Intent.ACTION_DIAL). I've tried checking the isIntentAvailable for this, but that doesn't seem to be the way to go.

like image 744
steve y Avatar asked Mar 04 '11 16:03

steve y


People also ask

How do I enable calls on my Android?

To allow calls or messages from people in your contacts list or only favorites to ring through, tap "Calls from" or "Messages from" and choose which contacts you want to allow.

What is phone call in Android?

We are able to make a phone call in android via intent. You need to write only three lines of code to make a phone call. Intent callIntent = new Intent(Intent.ACTION_CALL); callIntent.setData(Uri.parse("tel:"+8802177690));//change the number. startActivity(callIntent);


2 Answers

if (((TelephonyManager)getContext().getSystemService(Context.TELEPHONY_SERVICE)).getPhoneType()     == TelephonyManager.PHONE_TYPE_NONE) {     // no phone } 

EDIT I'm surprised it comes back PHONE_TYPE_CDMA. Here's another possibility:

if (((TelephonyManager)getContext().getSystemService(Context.TELEPHONY_SERVICE)).getLine1Number()     == null) {     // no phone } 

This will require the READ_PHONE_STATE permission.

like image 55
Ted Hopp Avatar answered Nov 09 '22 12:11

Ted Hopp


Devices do not necessarily need Context.TELEPHONY_SERVICE to make phone calls. Consider what happens if you install Skype:

  • Enter a phone number on the native Dialer/Phone app and press "Call".
  • A popup appears titled "Complete action using" and offering "Dialer" or "Skype" applications (it could list other applications too).

So, I believe Skype would work on a wifi-only device with no phone capabilities (according to Context.TELEPHONY_SERVICE).

I think you were correct with your original idea, but you need to check what applications are registered to handle Intent.ACTION_CALL instead of Intent.ACTION_DIAL, e.g.

Intent callIntent = new Intent(Intent.ACTION_CALL); callIntent.setData(Uri.parse("tel:5551231234")); List<ResolveInfo> callAppsList =    context.getPackageManager().queryIntentActivities(callIntent, 0); 

However, I am not aware of any reliable, forward-proof ways of figuring out if those applications will be able to handle the phone call. Consider these cases:

1) A wifi-only Xoom with Skype installed. It needs a valid wifi connection, and the user must have configured Skype to use their account, otherwise the call won't succeed.

2) A telephony enabled device with no SIM card in, or a SIM card that is locked or has run out. The device thinks it can handle telephony, but the call results in a "Not registered on network" error.

3) A telephony enabled device with no wifi or mobile connection (or because it is in Airplane/Flight mode). The device thinks it can handle telephony, but the call will fail.

There are ways you could detect some of these scenarios (e.g. inspecting getSystemService(Context.TELEPHONY_SERVICE).getSimState()), but I think this would probably lead to fragile code that may break when things change in future. For example, could you always reliably detect which application in the list is the default Dialer/Phone app? What if Android changed the package name for it in a subsequent release.

Hopefully that gave you some useful information - I wanted to show this is more tricky that it might appear at a first glance!

like image 29
Dan J Avatar answered Nov 09 '22 12:11

Dan J