ConnectivityManager主要管理和网络连接相关的操作,NetworkInfo类包含了对wifi和mobile两种网络模式连接的详细描述,通过其getState()方法获取的State对象则代表着连接成功与否等状态。
CONNECTED
Detailed state | Coarse-grained state |
IDLE | DISCONNECTED |
SCANNING | CONNECTING |
CONNECTING | CONNECTING |
AUTHENTICATING | CONNECTING |
CONNECTED | |
DISCONNECTING | DISCONNECTING |
DISCONNECTED | DISCONNECTED |
UNAVAILABLE | DISCONNECTED |
FAILED | DISCONNECTED |
ConnectivityManager.TYPE_WIFI 表示wifi连接
ConnectivityManager.TYPE_MOBILE 表示3G连接
网络设置Intent:
new Intent(android.provider.Settings.ACTION_WIRELESS_SETTINGS) // 跳转到无线网络设置界面
new Intent(android.provider.Settings.ACTION_WIFI_SETTINGS) // 跳转到无线wifi网络设置界面
最后别忘了在mainifest文件中加上权限:
"<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>"