Late to the pary, and I'm not sure about 29... and I guess it is quite lame... but this is how I did it:
public boolean isCellularAvailable()
{
TelephonyManager telephonyManager = (TelephonyManager)context.getSystemService(Context.TELEPHONY_SERVICE);
String opetarorName = telephonyManager.getNetworkOperatorName();
Log.i(LOG_TAG, "#### isCellularAvailable(): NetworkOperatorName is: " + opetarorName );
if (opetarorName .compareTo("") == 0)
{
Log.i(LOG_TAG, "#### isCellularAvailable(): NOPE");
Toast.makeText(context, "Turn off airplane mode and try again :)", Toast.LENGTH_LONG).show();
return false;
}
else
{
Log.i(LOG_TAG, "#### isCellularAvailable(): YES!");
return true;
}
}
The idea here is that if you are connected to a cellular network you should be able to get the name of your network provider.
If you get the name of one, then you are connected to that network, and should will be able to use it.
If you are in e.g. airplane mode, you will not be connected to a network, and will not get a name.
Noted that documentation says “Result may be unreliable on CDMA networks”… whatever that means.
But the “telephonyManager” offers a few similar functions, e.g. “getNetworkType()” might be another way to go if you know you´re favorable network types:
public boolean isCellularAvailable()
{
TelephonyManager telephonyManager = (TelephonyManager)context.getSystemService(Context.TELEPHONY_SERVICE);
int networkType = telephonyManager.getNetworkType();// .getNetworkOperatorName();
Log.i(LOG_TAG, "#### isCellularAvailable(): Network type is: " + networkType);
switch (networkType)
{
// Return true for networks that suits your purpose
case TelephonyManager.NETWORK_TYPE_1xRTT: return true;
case TelephonyManager.NETWORK_TYPE_CDMA: return true;
case TelephonyManager.NETWORK_TYPE_EDGE: return true;
case TelephonyManager.NETWORK_TYPE_EHRPD: return true;
case TelephonyManager.NETWORK_TYPE_EVDO_0: return true;
case TelephonyManager.NETWORK_TYPE_EVDO_A: return true;
case TelephonyManager.NETWORK_TYPE_EVDO_B: return true;
case TelephonyManager.NETWORK_TYPE_GPRS: return true;
case TelephonyManager.NETWORK_TYPE_GSM: return true;
case TelephonyManager.NETWORK_TYPE_HSDPA: return true;
case TelephonyManager.NETWORK_TYPE_HSPA: return true;
case TelephonyManager.NETWORK_TYPE_HSPAP: return true;
case TelephonyManager.NETWORK_TYPE_HSUPA: return true;
case TelephonyManager.NETWORK_TYPE_IDEN: return true;
case TelephonyManager.NETWORK_TYPE_IWLAN: return true;
case TelephonyManager.NETWORK_TYPE_LTE: return true;
//case TelephonyManager.NETWORK_TYPE_NR: return true; // Not supported by my API
case TelephonyManager.NETWORK_TYPE_TD_SCDMA: return true;
case TelephonyManager.NETWORK_TYPE_UMTS: return true;
// Return false for unacceptable networks, UNKNOWN id no network e.g. airplane mode.
case TelephonyManager.NETWORK_TYPE_UNKNOWN: return false;
// Future unknown network types, handle as you please.
default: return false;
}