Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
405 views
in Technique[技术] by (71.8m points)

wireless - Google Android - how to figure out if 3g and 2g is turned on

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.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...