如何检查互联网连接(WIFI /移动数据)被启用? [英] How to check if the Internet connection (Wifi/Mobile data) is ENABLED?

查看:199
本文介绍了如何检查互联网连接(WIFI /移动数据)被启用?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何检查互联网连接采用的是Android启用?就像如果位置服务被禁​​用,我们使用的技术

How to check if the internet connection is Enabled in Android? Like if the LOCATION SERVICE is disabled we use the technique

Location myLocation = locationmanager.getLastKnownLocation(provider);
if(myLocation == null){
      Show the AlertDialog.
}else{
do this.
}

就像这样,我如何检查Internet连接启用/禁用。

Like this, how do i check if the Internet connection is Enabled/Disabled.

推荐答案

您可以使用下面的方法:

You can use the following method:

ConnectivityManager conectivtyManager = (ConnectivityManager) ctx.getSystemService(Context.CONNECTIVITY_SERVICE);  
if (conectivtyManager.getActiveNetworkInfo() != null  
    && conectivtyManager.getActiveNetworkInfo().isAvailable()  
    && conectivtyManager.getActiveNetworkInfo().isConnected()) {  
    isConnected = true;  
} else {  
    isConnected= false;  
}  

希望它帮助!

这篇关于如何检查互联网连接(WIFI /移动数据)被启用?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆