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

99封情书 提交于 2019-11-28 20:50:30

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

You can also use ConnectivityManager. Something like that:

ConnectivityManager connectivityManager =(ConnectivityManager)mContext.getSystemService(Context.CONNECTIVITY_SERVICE); 
NetworkInfo activeNetInfo = connectivityManager.getActiveNetworkInfo();
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!