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

  • Home
  • SEARCH
  • 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 6798409
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T18:43:35+00:00 2026-05-26T18:43:35+00:00

I am working on online app. [Problem] when internet is down or not available

  • 0

I am working on online app. [Problem] when internet is down or not available it gives me error [Force close], I tried to handle using broadCast Receiver but not meet exact solution, looking for better solution.

public class MyBroadcastReceiver extends BroadcastReceiver {

@Override
public void onReceive(final Context context, final Intent intent) {

    NetworkInfo info = intent
            .getParcelableExtra(ConnectivityManager.EXTRA_NETWORK_INFO);

    if (null != info) {

        String state = info.getState().toString();

        if (state.equalsIgnoreCase("CONNECTED")) {
            SplashScreen.isWiFiConnected = true;
            Log.i("isWifiConnected", "=================TRUE");
        } else {
            SplashScreen.isWiFiConnected = false;
            Log.i("isWifiConnected", "=================FALSE");
        }

    }

}

}

thanks.

  • 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-05-26T18:43:36+00:00Added an answer on May 26, 2026 at 6:43 pm
    static String data = null;
    private static HttpPost httppost;
    private static HttpParams httpParameters;
    private static int timeoutConnection = 30000;
    private static HttpClient httpclient = null;
    private static HttpResponse response = null;
    private static int responseCode=0;
    public static ConnectivityManager mConnectivityManager;
    public static NetworkInfo mNetworkInfo;
    public static boolean isNetError=false;
    
    /** Post Http data and returns final string and status on network */
    
    public static void postHttp(String Url, Activity mActivity) {
    try {
        isNetError=false;
    
        mConnectivityManager= (ConnectivityManager) mActivity.getSystemService(Context.CONNECTIVITY_SERVICE);
        mNetworkInfo = mConnectivityManager.getActiveNetworkInfo();
    
        if (mNetworkInfo != null && mNetworkInfo.isConnectedOrConnecting())
        {
            httppost = new HttpPost(Url);
            httpParameters = new BasicHttpParams();
            HttpConnectionParams.setSoTimeout(httpParameters, timeoutConnection);
            httpclient = new DefaultHttpClient(httpParameters);
    
            List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>();
            nameValuePairs.add(new BasicNameValuePair("text", "some Text"));
    
    
            httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs, HTTP.UTF_8));
    
            // Execute HTTP Post Request
            response = httpclient.execute(httppost);
            data = EntityUtils.toString(response.getEntity());
    
        }
        else
            isNetError=true;
    
        } catch (Exception e) {
            e.printStackTrace();
            isNetError=true;
            }
    
       if (responseCode == 200)
       {
            isNetError=false;
            System.out.println("final..." + data);
            }
            else
                isNetError=true;
        }
    

    call this method in your doInBackground() of asyntask, and onPostExecute() check isNetError value and as mentioned in other answer of adding permission <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />

    if(isNetError)
    //No internet 
    else
    //do your stuff
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm working through the Stanford iPhone programming course online. The Presence app assignment pulls
I'm working with a app that has both online datastore(GAE) and an offline datastore(HTML5
we are using core data for our online catalog and its working fine and
I'm working on an online tool for students in my faculty to calculate their
I was working with a online game website. There are some event which call
I'm working on a online quiz client where we use a dedicated custom-made linux
I'm working on an online forex trading system and a while back we have
I am working on project -online file management where we have to tore file
I'm working on an online store. I have it setup on my testing server.
i am working on a online file management project.In which we are storing references

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.