Sanjana Nair
Sanjana Nair

Reputation: 2785

Check if device has cellular network or not

I have 7inch samsung Tab 4. It has cellular network only for internet but doesn't have phone feature. I have created an application to check if there is telephone feature All tabs/Phones work correctly with this condition except the tab that has only data service but not phone service.

How do I check this:

PackageManager pm = this.getPackageManager();
if (pm.hasSystemFeature(PackageManager.FEATURE_TELEPHONY))
{
  //PHONE DEVICE
}
else
{
  //TAB Device
}

How to fix this issue when there not telephone feature. Let me know!

Thanks!

Upvotes: 0

Views: 372

Answers (2)

cooplogic
cooplogic

Reputation: 31

In order to check if a device is a phone, it must be voice capable. The TelephonyManager has a method to explicitly get this value, isVoiceCapable(). This can be determined as follows:

TelephonyManager tm = 
   (TelephonyManager) getSystemService(Context.TELEPHONY_SERVICE);
if(tm.isVoiceCapable()) { 
    // PHONE
} else {
    // TABLET
}

If the TelephonyManager is not voice capable, then it is not a phone, but it may be data capable. More information can be found here.

Upvotes: 0

Chirag Chavda
Chirag Chavda

Reputation: 556

Try below code, it may help you.

if (((TelephonyManager) getSystemService(Context.TELEPHONY_SERVICE)).getPhoneType()
            == TelephonyManager.PHONE_TYPE_NONE || ((TelephonyManager) getSystemService(Context.TELEPHONY_SERVICE)).getLine1Number()
            == null) {
        // No Phone
        // Do as per your need
    } else {
        PackageManager pm = this.getPackageManager();
        if (pm.hasSystemFeature(PackageManager.FEATURE_TELEPHONY)) {
            //PHONE DEVICE
        } else {
            //TAB Device
        }
    }

This will require the READ_PHONE_STATE permission.

Upvotes: 1

Related Questions