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 7549905
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T10:04:30+00:00 2026-05-30T10:04:30+00:00

To detect whether internet is connected or not I am using the following code:

  • 0

To detect whether internet is connected or not I am using the following code:

             public boolean netConnect(Context ctx)
            {

                ConnectivityManager cm;
                NetworkInfo info = null;
                try
                {
                    cm = (ConnectivityManager) ctx.getSystemService(Context.CONNECTIVITY_SERVICE);
                    info = cm.getActiveNetworkInfo();
                }
                catch (Exception e)
                {

                    e.printStackTrace();
                }
                if (info != null)
                {
                    return true;

                }
                else
                {
                    return false;
                }
            }

Which is working perfectly fine .

But I want to know if the internet connection goes off at the time when app is downloading some files from server(I mean to say in between the process) is there anyway to detect that and display that internet connection lost or weak?

  • 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-30T10:04:31+00:00Added an answer on May 30, 2026 at 10:04 am

    You will have to use a BroadcastReceiver in all you Activities. I eventually ended up writing a super class for this.

    Now, whenever I write an App I do not extend Activity, I always extends a dummy class that I create say MyActivity. That way whenever a requirement changes I only change MyActivity and all my classes are updated.

    For your particular case, I wrote a superclass that is available at : https://github.com/sfarooq/A-droid-lib/
    Look at the ConnectedActivity class in the network package. It shows a dialog whenever connection is lost and dismisses it when connection is restored. To use it just extend ConnectedActivity in the Activities you want. To use it throughout the app, I would recommend making your own superclass as mentioned above and have that extend ConnectedActivity so you are able to change stuff later (also helpful if you want to add custom dialog and menus later, you’ll only have to add it to your super class).

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

Sidebar

Related Questions

I'm using the following code to detect whether the browser being used on my
How to detect whether or not a particular font is installed using javascript only.
my app accesses the internet and i just want to detect whether there is
How can my vbscript detect whether or not it is running in a UAC
I need to detect whether my Makefile is running under valgrind (indirectly, using valgrind
Is there a way to detect whether IIS is enabled or not? I know
How can I programmatically detect whether or not two triangles touch each other, given
I need a way to programatically detect whether the monitor is wide or not,
The sample method below is intended to detect whether or not it has been
I would like to detect whether the user has pressed Enter using jQuery. How

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.