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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T23:18:47+00:00 2026-05-20T23:18:47+00:00

What I really want is, when the user has no connection, I want to

  • 0

What I really want is, when the user has no connection, I want to show some dialog that he or she has no connection.

I tried to put this on my MainActivity but still didn’t work.

public boolean isOnline() {
 ConnectivityManager cm = (ConnectivityManager) getSystemService(Context.CONNECTIVITY_SERVICE);
 return cm.getActiveNetworkInfo().isConnectedOrConnecting();

}

I also used this one but it didn’t also work:

public class ConnectionChangeReceiver extends BroadcastReceiver
    {
      @Override
      public void onReceive( Context context, Intent intent )
      {
        ConnectivityManager connectivityManager = (ConnectivityManager) context.getSystemService( Context.CONNECTIVITY_SERVICE );
        NetworkInfo activeNetInfo = connectivityManager.getActiveNetworkInfo();
        NetworkInfo mobNetInfo = connectivityManager.getNetworkInfo(     ConnectivityManager.TYPE_MOBILE );
        if ( activeNetInfo != null )
        {
          Toast.makeText( context, "Active Network Type : " + activeNetInfo.getTypeName(), Toast.LENGTH_SHORT ).show();
        }
        if( mobNetInfo != null )
        {
          Toast.makeText( context, "Mobile Network Type : " + mobNetInfo.getTypeName(), Toast.LENGTH_SHORT ).show();
        }
      }
    }

I added this on my manifest:

<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />

Can someone tell me what I’m doing wrong, I would really appreciate it a lot. Thanks in advance!

  • 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-20T23:18:48+00:00Added an answer on May 20, 2026 at 11:18 pm

    Maybe this link can help you a bit further: Broadcastreceiver to obtain ServiceState information

    You could past the mentined CommunicationManager code in your activity, or better, if you need access from more activities, you could also declare the class as static in the Application Singletin instance and call it from there as described here

    You also need to register the BroadcastReceiver in your application manifest:

    <receiver android:enabled="true" android:name="com.project.mobile.controller.comm.ConnectivityReceiver">
        <intent-filter>
            <action android:name="android.net.conn.CONNECTIVITY_CHANGE"/>
        </intent-filter>
    </receiver>
    

    Enjoy

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

Sidebar

Related Questions

I really want to get this to work, but I feel like I've been
Really simple question: From within GWT I want to forward the user away from
I really want Resharper to format my line-wrapped ternaries in this way return navigator.IsTerminating
Maybe my title is not the best but here is what I really want.I
I am developing a website that has some sort of realtime update. Now the
I want to include a function on my page, that checks whether the user
I need some way to detect when the network connection has been lost. So
In my Caliburn Bootstrapper, I am trying to validate that a user has permissions
I'm really struggling to wrap my head around some of this stuff. Let me
I want to create a new Rally user with the following C# code DynamicJsonObject

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.