Android 中判断网络状态是否连接 发表于 2015-02-02 | 在Activity 中判断网络状态在Android 中,我们经常会判断网络,Anddroid 官方提供了这样的解决方式,可以用来判断是否连接网络。 当然了,也别忘记要在清单文件注册获取网络状态的权限。 使用单例模式来判断网络 当然上面的代码也有弊端,获取getSystemService() 方法必须是有默认上下文的,才可以获取的,但是获取网络状态又是很频繁,我们将它抽离出来,放到工具类中。我们通过getInstance() 传入上下文。 最后我们在Activity 中就可这样使用了。 参考 Determining and Monitoring the Connectivity Status Detect whether there is an Internet connection available on Android [duplicate] 欢迎关注我的公众号:安卓同学(ID:AndroidMate)