最新下载
热门教程
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
Android编程判断是否连接网络的方法【WiFi及3G判断】
时间:2017-05-10 编辑:简简单单 来源:一聚教程网
判断wifi网络是否链接:
代码如下 | 复制代码 |
publicstaticbooleanisWiFiActive(Context inContext) { WifiManager mWifiManager = (WifiManager) inContext .getSystemService(Context.WIFI_SERVICE); WifiInfo wifiInfo = mWifiManager.getConnectionInfo(); intipAddress = wifiInfo ==null?0: wifiInfo.getIpAddress(); if(mWifiManager.isWifiEnabled() && ipAddress !=0) { System.out.println("**** WIFI is on"); returntrue; }else{ System.out.println("**** WIFI is off"); returnfalse; } } |
判断3G网络是否链接:
代码如下 | 复制代码 |
publicstaticbooleanisNetworkAvailable( Context context) { ConnectivityManager connectivity = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE); if(connectivity ==null) { System.out.println("**** newwork is off"); returnfalse; }else{ NetworkInfo info = connectivity.getActiveNetworkInfo(); if(info ==null){ System.out.println("**** newwork is off"); returnfalse; }else{ if(info.isAvailable()){ System.out.println("**** newwork is on"); returntrue; } } } System.out.println("**** newwork is off"); returnfalse; } |
相关权限:
代码如下 | 复制代码 |
相关文章
- sora软件价格介绍 02-22
- sora官网入口地址一览 02-22
- Sora生成的视频使用教程 02-22
- 《梦幻西游》元宵灯谜线索答案大全2024 02-22
- 《原神》有朋自远方来第一天通关攻略 02-22
- 《苏醒之路》四个结局达成攻略 02-22