如何在 Android 设备上检查电话网络 [英] How to check for phone network on Android devices

查看:52
本文介绍了如何在 Android 设备上检查电话网络的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我知道如何检查我是否可以访问互联网 (使用这篇文章中的代码),但是是否可以检查手机是否可以访问电话网络?例如,某人可能可以通过 Wifi 访问互联网,但无法通过电话网络访问来发送短信或拨打电话.

I know how to check if I have internet access (using the code from this post),but is it possible to check if a phone has telephone network access? For example someone might have access to the internet via Wifi but not have phone network access to send SMS or make calls.

就我而言,在使用真实设备(三星 Galaxy S)时,我可以关闭我的 3G 网络(然后手机会检测到我没有连接到互联网),但我仍然可以制作手机打电话和发送短信.我想我一定是在使用其他网络...

In my case, while using a real device (Samsung Galaxy S), I am able to turn of my 3G network (then the phone will detect I am not connected to the internet), but I am still able to make phone calls and send SMS. I guess I must be using some other network...

如何测试手机网络是否连通?我需要 TelephonyManager 吗?

How do I test whether the phone network is connected? Do I need the TelephonyManager?

感谢您抽出宝贵时间.

梅尔

推荐答案

你肯定不会只用这个: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

这篇关于如何在 Android 设备上检查电话网络的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆