Android 检查当前是否已经连接上 Internet
这段代码用来在程序中检查当前是否已经联网
[代码] java代码
1 |
ConnectivityManager con=(ConnectivityManager)getSystemService(Activity.CONNECTIVITY_SERVICE); |
2 |
boolean wifi=con.getNetworkInfo(ConnectivityManager.TYPE_WIFI).isConnectedOrConnecting(); |
3 |
boolean internet=con.getNetworkInfo(ConnectivityManager.TYPE_MOBILE).isConnectedOrConnecting(); |
[代码] AndroidManifest.xml
1 |
< uses-permission android:name = "android.permission.ACCESS_NETWORK_STATE" /> |
一起学习GIS及其二次开发,一起进步!