Android - Programmatically check internet connection and display dialog if notConnected

后端 未结 14 2491
予麋鹿
予麋鹿 2020-12-15 04:04

I am working on a live project. and when user click on the app. the welcome screen appears(there is a webview on that screen). and if the internet is not connected then the

14条回答
  •  执念已碎
    2020-12-15 04:55

    Check internet connection

     ConnectivityManager mgr = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
     NetworkInfo netInfo = mgr.getActiveNetworkInfo();
    
            if (netInfo != null) {
                if (netInfo.isConnected()) {
                    // Internet Available
                }else {
                   //No internet
                }
            } else {
                //No internet
            }
    

提交回复
热议问题