Flav
Flav

Reputation: 237

How to check if an Android device has voice capabilities

Does anyone know a good way of programmaticaly checking if an Android device, phone or tablet, has voice capabilities? By voice capabilities I mean capability to make phone calls. I know there are devices, like Galaxy tab in North America, that don't have this capability.

Upvotes: 4

Views: 4099

Answers (4)

LargeGlasses
LargeGlasses

Reputation: 912

I know this question was posted a long time ago, but I still thought I would post the solution I came up with that works for me so far, just so anyone with the same problem can benefit. (Because it seems like lots of people are having trouble finding a solution).

I just checked for the device's voicemail number, and obviously if it doesn't have one, then it is not a phone. In my code, to check this, it is tm.getVoiceMailNumber();

Here's what I did:

callButton.setOnClickListener(new View.OnClickListener() {

        public void onClick(View v) {

            TelephonyManager tm = (TelephonyManager)getSystemService(TELEPHONY_SERVICE);
            String ableToMakePhoneCalls = tm.getVoiceMailNumber(); //check device for voicemail number (null means no voicemail number).

            if(ableToMakePhoneCalls == null){ //If the device does not have voicemail, then it must not be a phone. So it can't call.

                //I displayed an alert dialog box here


            }
            else{

                String phoneNum = "tel:8885554444";

                Intent intentPhone = new Intent(android.content.Intent.ACTION_CALL);
                intentPhone.setData(Uri.parse(phoneNum));

                startActivity(intentPhone);
            }
        }
    });

Upvotes: 1

Phil
Phil

Reputation: 36289

I would assume that prepare() would fail if there is not mic available:

  mRecorder = new MediaRecorder();
  mRecorder.setAudioSource(MediaRecorder.AudioSource.MIC);
  mRecorder.setOutputFormat(MediaRecorder.OutputFormat.THREE_GPP);
  mRecorder.setOutputFile(audio_file);
  mRecorder.setAudioEncoder(MediaRecorder.AudioEncoder.AMR_NB);
  try {
      mRecorder.prepare();
      mRecorder.start();
  } catch (Exception e) {}

Upvotes: 0

mag382
mag382

Reputation: 756

I haven't tried this myself, but it looks like the details you need would be in the TelephonyManager:

private boolean hasPhoneAbility()
{
   TelephonyManager telephonyManager = (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE);
   if(telephonyManager.getPhoneType() == TelephonyManager.PHONE_TYPE_NONE)
       return false;

   return true;
}

Upvotes: 3

Ted Hopp
Ted Hopp

Reputation: 234795

In theory, you should be able to use Intent.resolveActivity to do this. There's a problem (described here) with Galaxy tabs in particular. They evidently report that they have calling capability. You can even resolve an intent successfully. Unfortunately, it resolves to a no-op activity.

Upvotes: 0

Related Questions