How do I know if the device is Smathphone or Tablet and/or is able to send SMS?

Asked

Viewed 70 times

1

I developed an application that is able to send an SMS with some information just at the touch of a button, but one question that worries me is the devices that do not have the ability to send SMS, like tablet’s without SIM card.

Is there any way I can validate this situation? Know if there is a SIM card present?

1 answer

3

Use the class Telephonymanager.

By the method getPhoneType() can you know if it’s phone and your type.

TelephonyManager telephonyManager = (TelephonyManager) getSystemService(Context.TELEPHONY_SERVICE);
if(telephonyManager.getPhoneType() == TelephonyManager.PHONE_TYPE_NONE){
    //não é telefone
}

If you are a phone, you can know the status of the SIM by using the method getSimState().

TelephonyManager telephonyManager = (TelephonyManager) getSystemService(Context.TELEPHONY_SERVICE);
int phoneType = telephonyManager.getPhoneType();
if(phoneType == TelephonyManager.PHONE_TYPE_NONE){
    //não é telefone
}else if(phoneType == TelephonyManager.PHONE_TYPE_GSM){
    if(telephonyManager.getSimState() == TelephonyManager.SIM_STATE_READY){
        //Tem SIM e está pronto a usar
    }
}

See documentation for possible values returned by getPhoneType() and getSimState().

Browser other questions tagged

You are not signed in. Login or sign up in order to post.