判断Android手机是否联网

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里面加个权限


文档如下:
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修改当前窗口的亮度
  2. Android手机游戏摇杆
  3. Android当前时间的获取
  4. Delphi XE5 Android(安卓)调用手机震动
  5. android 判断耳机是否插入的几种方式
  6. Android应用程序启动过程源代码分析(2)
  7. 【Android】判断某个AP是否在系统中存在(PackageManager与Package
  8. 修改 android 手机 hosts 文件的方法
  9. Android中判断网络连接是否可用

随机推荐

  1. Android(安卓)Shape 形状
  2. Android的NDK开发(3)————JNI数据类型
  3. Android(安卓)Vertical TextView 文字竖
  4. 初学Android之小随笔2--SurfaceView
  5. Android之省市县三级联动
  6. 收集android上开源的酷炫的交互动画和视
  7. android 程序截图功能
  8. Android检查网络是否连接
  9. 监测Android(安卓)Market是否被下过
  10. android之【本地通知Notification】