开发者

Is there a way to tell if an android device is wifi-only?

I am trying to find a reliable way to tell if an Android device is wifi-only. I tried a couple of ways:

-- Try to get device ID (IMEI/MEID), if I can not get the IMEI/MEID number, then I can assume the device is wifi-only. This doesn't work as some phones do not return a device ID when they are put in flight mode. -- Try to read TelephonyManager.getPhoneType. This doesn't work either as the wifi-only device I am testing with returns PHONE_TYPE_GSM, while I expect it to return PHONE_TYPE_NON开发者_JAVA技巧E.

I wonder if anyone has successfully distinguish wifi-only devices and the non-wifi-only ones.


You could query the system features in your app to see if that works.

PackageManager pm = getPackageManager();
boolean isAPhone = pm.hasSystemFeature(PackageManager.FEATURE_TELEPHONY);

If you care about GSM/CDMA use the more specific FEATURE_TELEPHONY_GSM or FEATURE_TELEPHONY_CDMA.

If the device is lying there is of course not much you can do afaik.


Following solution worked for me better:

TelephonyManager mgr = (TelephonyManager)ctx.getSystemService( Context.TELEPHONY_SERVICE );
return mgr.getPhoneType() != TelephonyManager.PHONE_TYPE_NONE;

And following did NOT work on few devices like Nook Tablet:

PackageManager pm = ctx.getPackageManager();
return pm.hasSystemFeature( PackageManager.FEATURE_TELEPHONY );


I have a similar problem to yours and I checked out several solutions. Only one of them works reliably thus far

if (mContext.getSystemService(Context.TELEPHONY_SERVICE) == null) {
    // wifi-only device
}

This assumption is wrong. My wifi-only Nexus 7 returns a Telephony Manager object.

mContext.getPackageManager().hasSystemFeature(PackageManager.FEATURE_TELEPHONY)

This returns false on both my Nexus 7. One of them supports data connections and the other one is wifi-only

TelephonyManager telMgr = mContext.getSystemService(Context.TELEPHONY_SERVICE)
telMgr.getPhoneType()

I expect PHONE_TYPE_NONE for the nexus 7 that is wifi-only and PHONE_TYPE_GSM for the other Nexus 7. I get PHONE_TYPE_NONE for both Nexus 7

if(telMgr.getSimState() == TelephonyManager.SIM_STATE_UNKNOWN) {
    // Wifi-only device
}
else if (telMgr.getSimState() == TelephonyManager.SIM_STATE_ABSENT) {
    // Device that supports data connection, but no SIM card present
}

This solution worries me. SIM_STATE_UNKNOWN is also used during state transitions. Also, some devices support data connections but don't have a SIM card.

My favourite solution is the following

ConnectivityManager mConMgr = mContext.getSystemService(Context.CONNECTIVITY_SERVICE)
if (mConMgr.getNetworkInfo(ConnectivityManager.TYPE_MOBILE) == null) {
    //wifi-only device
}

The only thing that worries me is if there are devices which support TYPE_MOBILE_HIPRI or TYPE_MOBILE_MMS but not TYPE_MOBILE I suspect this is not the case.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜