开发者

how can I check whether device can access Internet via active WiFi Connection?

开发者 https://www.devze.com 2023-03-02 09:41 出处:网络
I am referring to a situation when device is connected to access point but for some reason is blocked from accessing i开发者_Python百科nternet using this AP.for check wifi is enabled or not

I am referring to a situation when device is connected to access point but for some reason is blocked from accessing i开发者_Python百科nternet using this AP.


for check wifi is enabled or not

 WifiManager wfManager = (WifiManager)getSystemService(Context.WIFI_SERVICE);
if(wfManager.isWifiEnabled())
{
    //Code
}
else  
{
 //Code
 }

for check internet connection..

public boolean isOnline() 
{
     ConnectivityManager cm = (ConnectivityManager) getSystemService(Context.CONNECTIVITY_SERVICE);
     NetworkInfo netInfo = cm.getActiveNetworkInfo();

    if (netInfo != null && netInfo.isConnectedOrConnecting()) 
    {
            //Try This 
            int i =netInfo.getType() ; 
            System.out.println("Net Type ="+i);    

            return true;
    }
    return false;

}


private boolean connectionAvailable() {
    boolean connected = false;
    ConnectivityManager connectivityManager = (ConnectivityManager) getSystemService(Context.CONNECTIVITY_SERVICE);
    if (connectivityManager.getNetworkInfo(ConnectivityManager.TYPE_WIFI).getState() == NetworkInfo.State.CONNECTED) {
        //we are connected to a network
        connected = true;
    }
    return connected;
}


These look like something that can solve the problem:

How to do a true Java ping from Windows?

How to check if internet connection is present in java?

Detect internet Connection using Java

0

精彩评论

暂无评论...
验证码 换一张
取 消