安卓:如何检查3G是否启用或不? [英] Android: How to check whether 3G is enabled or not?

查看:125
本文介绍了安卓:如何检查3G是否启用或不?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要知道3G连接是否允许在设备上还是不行。我不想知道什么是当前的网络状态,因为如果你设置的网络模式中的移动网络设置屏幕设置为自动网络状态可以是2G或3G。我只是想知道哪些设定中选择了那里 - 2G,3G或自动(后两者对我来说意味着相同)。

I need to know whether 3G connectivity is permitted on the device or not. I don't want to know what current network state is, because if you set "Network Mode" setting in "Mobile network settings" screen to "Automatic" network state could be either 2G or 3G. I just want to know which setting is selected there - 2G, 3G or Automatic (latter two mean the same for me).

两者 telephonyManager.getNetworkType() ConnectivityManage.getNetworkInfo(ConnectivityManager.TYPE_MOBILE).getState()

正在返回当前的网络状态,从而导致我在一个错误的方向,因为如果目前的状态是2G的,这可能意味着3G是禁用或者只是3G模式处于特定位置不可用。

are returning current network state, which can lead me in a wrong direction, because if current state is 2G it could mean that 3G is disabled or just that 3G mode is unavailable at the specific location.

推荐答案

的LG GT540手机测试后更新:

您可以使用 Settings.Secure 阅读preferred网络模式,在这种code:

You can use Settings.Secure to read preferred network mode, as in this code:

ContentResolver cr = getContentResolver();
int value = Secure.getInt(cr, "preferred_network_mode");

在我的LG GT540与CM 7.1固件,我有四个选项:

On my LG GT540 with CM 7.1 firmware, I have four options:


  • GSM / WCDM(自动) - 在code以上的回报 3

  • 只有WCDMA - 在code以上的回报 2

  • 仅GSM - 在code以上的回报 1

  • GMS / WCDMA(WCMDA preferred) - 在code以上的回报 0

  • GSM/WCDM (auto) - the code above returns 3
  • WCDMA only - the code above returns 2
  • GSM only - the code above returns 1
  • GMS/WCDMA (WCMDA preferred) - the code above returns 0

当然,GSM是2G和WCDMA 3G是。请注意,这并不为您提供哪些连接是当前活动的信息(前提是你让两者)。对于这一点,看到@ VikashKLumar的回答。

Naturally, GSM is 2G and WCDMA is 3G. Note that this does not provide you with information on which connection is currently active (provided you allow both). For that, see @VikashKLumar's answer.

这篇关于安卓:如何检查3G是否启用或不?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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