我知道如何检查是否有互联网接入(using the code from this post),,但是否可以检查电话是否有电话网络接入?例如,有些人可能可以通过Wifi访问互联网,但不能通过电话网络发送SMS或打电话。
在我的例子中,当使用真正的设备(三星Galaxy S)时,我可以打开我的3G网络(然后手机会检测到我没有连接到互联网),但我仍然可以打电话和发送SMS。我想我一定是在用别的网络。
如何测试电话网络是否连通?我需要TelephonyManager吗?
感谢您的宝贵时间。
Mel
发布于 2011-04-03 21:03:48
当然,你不会仅仅使用这个:getNetworkType()
boolean hasNetwork = android.telephony.TelephonyManager.getNetworkType() != android.telephony.TelephonyManager.NETWORK_TYPE_UNKNOWN;
// True if the phone is connected to some type of network i.e. has signal
发布于 2013-03-17 16:35:19
上面的答案对我的一个应用程序用户不起作用--他已经连接到网络,但他的NetworkType未知。截图:http://dl.dropbox.com/u/5072192/SC20130317-161413.png
相反,我正在检查NetworkOperator字段。(从这里的第一个答案What is the correct way of checking for mobile network available (no data connection))
public static boolean isMobileAvailable(Context acontext) {
TelephonyManager tel = (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE);
return (tel.getNetworkOperator() != null && !tel.getNetworkOperator().equals(""));
}
https://stackoverflow.com/questions/5529484
复制相似问题