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 1.6全部的权限介绍
  2. Android 中各种权限深入体验及详解
  3. android:sharedUserId权限问题
  4. Android权限问题
  5. 关闭Android root权限
  6. 如何使Android应用程序获取系统权限【转】
  7. android M 运行时权限申请流程

随机推荐

  1. Android遥控器定制改变焦点
  2. Android 系列之Android 命令行手动编译打
  3. android material design 主题
  4. Android布局之LinearLayout
  5. Android之七 闪屏的实现
  6. Android Settings 设置中 PreferenceActi
  7. Android Activity 属性介绍
  8. android studio 的自动更新问题
  9. Android添加快捷方式(Shortcut)到手机桌
  10. Android之辅助服务下篇————Accessibi