Google Android - 如何确定 3g 和 2g 是否已打开

发布于 2024-07-18 03:23:38 字数 636 浏览 16 评论 0原文

我正在为 Google Android 开发一个简单的应用程序来打开和关闭 wifi 或 3g 或 2g。

我看到 http://developer.android.com/参考/android/net/wifi/WifiManager.html#isWifiEnabled() 您可以查看 wifi 是否启用或禁用以及我们 http://developer.android.com/reference /android/net/wifi/WifiManager.html#setWifiEnabled(boolean) 打开和关闭 wifi。

我想知道是否可以对 3G 和 2G/GPRS 做同样的事情? 我知道这是可能的,因为您可以关闭 3G 并保留 2G。

I'm developing a simple application for the Google Android to turn on and off the wifi or 3g or 2g.

I see http://developer.android.com/reference/android/net/wifi/WifiManager.html#isWifiEnabled()
that you can see if the wifi is enabled or disabled and also us
http://developer.android.com/reference/android/net/wifi/WifiManager.html#setWifiEnabled(boolean)
to turn on and off the wifi.

I'm wondering if it's possible to do the same for 3G and for 2G/GPRS?
I know it's possible because you can turn off 3G and left 2G on.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

云淡风轻 2024-07-25 03:23:38

2G/3G

要确定您的网络类型使用:

TelephonyManager.getNetworkType();

这里有一些示例代码:

bool is3G = (manager.getNetworkType() == TelephonyManager.NETWORK_TYPE_UMTS);

该类的文档可以在以下位置找到:TelephonyManager

开/关

要检查您的电话收音机是否打开或关闭,请使用:

ServiceState.getState();

要设置它,请使用:

ServiceState.setState(STATE_POWER_OFF);

目前尚不清楚 setState 方法是否存在于所有设备和所有状态下的功能上。 没有关于此方法的文档。 该类的文档可以在以下位置找到: ServiceState

此问题也可能是相关:http://code.google.com/p/android/issues /detail?id=1065

2G/3G

To determine your network type use:

TelephonyManager.getNetworkType();

here's some example code:

bool is3G = (manager.getNetworkType() == TelephonyManager.NETWORK_TYPE_UMTS);

Docs for the class can be found at: TelephonyManager

On/Off

To check if your telephone radio is on or off use:

ServiceState.getState();

To set it use:

ServiceState.setState(STATE_POWER_OFF);

It's unclear whether the setState method exists on all devices and functions in all states. There is no documentation for this method. Documentation for the class can be found at: ServiceState

This issue might also be relevant: http://code.google.com/p/android/issues/detail?id=1065

怼怹恏 2024-07-25 03:23:38

您还可以使用 ConnectivityManager。 像这样的东西:

ConnectivityManager connectivityManager =(ConnectivityManager)mContext.getSystemService(Context.CONNECTIVITY_SERVICE); 
NetworkInfo activeNetInfo = connectivityManager.getActiveNetworkInfo();

You can also use ConnectivityManager. Something like that:

ConnectivityManager connectivityManager =(ConnectivityManager)mContext.getSystemService(Context.CONNECTIVITY_SERVICE); 
NetworkInfo activeNetInfo = connectivityManager.getActiveNetworkInfo();
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文