Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7726627
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T05:15:47+00:00 2026-06-01T05:15:47+00:00

An UnknownHostException is thrown if a server is down or if there is no

  • 0

An UnknownHostException is thrown if a server is down or if there is no internet connection. How can I determine if the UnknownHostException is thrown because the server is down or there is no internet connection?

The reason for this is I need to notify the user about the cause of the error. And I have to display something like this “Sorry. The service is currently not available. Please try again later” or “You do not have an internet connection”.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-01T05:15:48+00:00Added an answer on June 1, 2026 at 5:15 am

    You could check the network state to determine if an internet connection is available (not 100% reliable though):

    ConnectivityManager conMgr =  (ConnectivityManager)getSystemService(Context.CONNECTIVITY_SERVICE);
    
    if ( conMgr.getNetworkInfo(0).getState() == NetworkInfo.State.CONNECTED 
        ||  conMgr.getNetworkInfo(1).getState() == NetworkInfo.State.CONNECTING  ) {
    ...
    }
    

    EDIT :

    IMHO, there is no way to tell for sure that the phone internet connectivity is down.
    But you could, in addition to checking the network state, make a simple test like downloading a small page from a website on the internet (pick some reliable server).

    The result of this double test should be accurate 99% of the time.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

This questions is related to java exceptions, why are there some cases that when
failed to open file file://D/:/dev/test_all.html JavaException: java.net.UnknownHostException: D Any ideas for why this happens?
I'm trying to implement a server-client socket program in Java that can support multiple
dedicated Linux server throws UnknownHostException. InetAddress addr; try { addr = InetAddress.getLocalHost(); } catch
Can anybody tell my why this doesn't work in the Android emulator? From the
I've an UnknownHostException when i used this method for uploading files from ddms: try
I have done lots of research on this and tried every method out there
I am trying to make an HTTPClient connection using sockets and can't figure it
When I'm trying to set up a socket server, I've got an error message:
Im currently wishing to transfer data from a remote server by capturing printed data

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.