Android - Programmatically check internet connection and display dialog if notConnected

后端 未结 14 2513
予麋鹿
予麋鹿 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:45

    I've tried different methods described above, besides it I've been caught in some cases. So finally, I'm using below code snippet to make a network call...

    try {
        InetAddress address = InetAddress.getByName("www.stackoverflow.com");
        //Connected to working internet connection
    } catch (UnknownHostException e) {
        e.printStackTrace();
        //Internet not available
    }
    

    This can be useful in many perspectives. If something is not fine in this approach, please let me know.

提交回复
热议问题