android 中查看当前是否联网
方法如下:
ConnectivityManager cManager=(ConnectivityManager)getSystemService(Context.CONNECTIVITY_SERVICE);
NetworkInfo info = cwjManager.getActiveNetworkInfo();
if (info != null && info.isAvailable()){
//do something
//能联网
return true;
}else{
//do something
//不能联网
return false;
}
如果为True则表示当前Android手机已经联网,可能是WiFi或GPRS、HSDPA等等,具体的可以通过 ConnectivityManager 类的getActiveNetworkInfo() 方法判断详细的接入方式。

同时要在manifest里面加个权限
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>

文档如下:
boolean android.net.NetworkInfo.isAvailable()

public boolean isAvailable ()
Indicates whether network connectivity is possible. A network is unavailable when a persistent or semi-persistent condition prevents the possibility of connecting to that network. Examples include

The device is out of the coverage area for any network of this type.
The device is on a network other than the home network (i.e., roaming), and data roaming has been disabled.
The device's radio is turned off, e.g., because airplane mode is enabled.

Returns
true if the network is available, false otherwise

更多相关文章

  1. Android的权限 permission
  2. 在android获取root权限的方法^_^。
  3. Android学习笔记_20_访问应用权限汇总
  4. Android系统权限和root权限
  5. [Android Pro] Android fastboot刷机和获取Root权限
  6. Android文档资源大放送 感兴趣的话可以网盘下载(个人收集)
  7. App 权限一点知识
  8. Android应用程序的权限列表
  9. android 的权限

随机推荐

  1. Android获取本机Mac地址及IP地址方法
  2. 关于android在Service中弹出Dialog对话框
  3. Professional Android 2 Development - 6
  4. Android 异步任务加载图片代码
  5. Android USB挂载
  6. Android中Log信息的输出方法
  7. sqlite数据库默认自增标号RecNo与integer
  8. 安卓Android大量项目源码实例
  9. 在4.0以上系统中应用出现2.3版本的系统UI
  10. 2013.07.11——— android MediaRecorder