1

The question. I'm getting error on this line:

android.net.NetworkInfo.State mobile = con.getNetworkInfo(0).getState(); 

The error you are giving Tablets that have no 3G connection can only connect through WI-FI. Is there a way to ask if the device lacks 3G connection?

ivan arias
  • 39
  • 6

3 Answers3

0
if(NetworkInfo.getType == ConnectivityManager.TYPE_MOBILE) {

    // .getState() here
}
XorOrNor
  • 8,868
  • 12
  • 48
  • 81
0

Assuming that you are happy to find out whether the tablet has a cellular radio or not, how about:

@Override
public boolean hasCellularRadio() {
    TelephonyManager telephonyManager = (TelephonyManager)
            mContext.getSystemService(Context.TELEPHONY_SERVICE);
    String deviceId = telephonyManager.getDeviceId();
    if (deviceId == null || deviceId.isEmpty()) {
        return false;
    }
    return true;
}
snodnipper
  • 2,580
  • 1
  • 29
  • 19