SoFunction
Updated on 2025-03-01

An example explanation of android detection network connection status


/**
* If you visit Baidu homepage, if the network is not available, you need to set it
 */ 
private void initMoreGames() { 
    String URL_MOREGAMES = ""; 
    mWebView = (WebView) findViewById(.view_gamesort); 

    if (mWebView != null) { 
        (); 
        WebSettings webSettings = (); 
        if (webSettings != null) { 
            (true); 
            (MODE_PRIVATE); 
            ("utf-8"); 
        } 

// Determine whether the network is available
        if(isOpenNetwork() == true) { 
            (URL_MOREGAMES); 
        } else { 
            builder = new (); 
("No network available").setMessage("Does the network be set?");

("Yes", new () {
                @Override 
                public void onClick(DialogInterface dialog, int which) { 
                    Intent intent = null; 

                    try { 
                        String sdkVersion = ; 
                        if((sdkVersion) > 10) { 
                            intent = new Intent(.ACTION_WIRELESS_SETTINGS); 
                        }else { 
                            intent = new Intent(); 
                            ComponentName comp = new ComponentName("", ""); 
                            (comp); 
                            (""); 
                        } 
                        (intent); 
                    } catch (Exception e) { 
                        (TAG, "open network settings failed, please check..."); 
                        (); 
                    } 
                } 
}).setNegativeButton("No", new () {
                @Override 
                public void onClick(DialogInterface dialog, int which) { 
                    ();         
                    finish(); 
                } 
            }).show(); 
        } 
    } else { 
        (TAG, "mWebView is null, please check..."); 
    } 
}