开发者

how to mange wifi internet connectivity in android?

i use following code to check 3g,edge connectivity in android phone application

public boolean isConnected()
    {
        try
        {
            final ConnectivityManager conn_manager = (ConnectivityManager) 
            this.getSystemService(Context.CONNECTIVITY_SERVICE);

            final Network开发者_开发百科Info network_info = conn_manager.getActiveNetworkInfo();
            if ( network_info != null && network_info.isConnected() ) 
            {
                return true;
            }
            else
            {
                return false;
            }
        }
        catch (Exception e) 
        {
            return false;

        }
    }

if i connect it to wifi then this check does not work correctly actually when wifi is connected to network and internet coverage is not there above check say ok infact its wrong any one guide me how to handle packet lost case like

internet comming then disconnnecting and this process keeps continue in android ? or am i doing something wrong?

any help would be appreciated.


if i connect it to wifi then this check does not work correctly

Yes, it does, by your own admission.

actually when wifi is connected to network and internet coverage is not there above check say ok

That is what it is supposed to do. Your WiFi network is active, meaning Android is in communication with your access point. That is what "connected" means.

The only way you can tell if you can communicate to some host is to try to communicate to some host. Note that requestRouteToHost() reportedly has issues, so you would need to try something else (e.g., make an HTTP connection to a known good URL).

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜