0

Hi guys I'm new on android and I wish to check every "some" seconds if the internet connection has been turned on from the user.

This is my situation: I've a map on a fragment and I download from my app an xml file with the position of markers, titles, addresses, and many other things. Now if the person that download my app don't have the internet turned on, I can't place any markers on the map. So a popup come out that request to activate an internet connection. But if the person activate it without refresh the main activity nothing happens.

So how can I do it? Which methods I have to use?

Pierpaolo Ercoli
  • 1,028
  • 2
  • 11
  • 32
  • 2
    should see : http://stackoverflow.com/questions/6169059/android-event-for-internet-connectivity-state-change – Hacketo Sep 29 '14 at 12:42
  • 1
    see here: http://stackoverflow.com/a/3767766/1809221 – Manu Zi Sep 29 '14 at 12:43
  • @Hacketo watch my question edit please. And in the link you provided to me, what I have to write on " Android:name"?? thank you so much – Pierpaolo Ercoli Sep 29 '14 at 13:02
  • typically you would do : a/ popup requesting internet access b/ redirect to internet settings c/ check again when the user comes back to your app. d/ go to a. (as is done in google navigation for GPS) – njzk2 Sep 29 '14 at 13:09
  • Thank you all I solved with the link from @Hacketo; I didn't read all replies below. Thank you so much. – Pierpaolo Ercoli Sep 29 '14 at 13:15
  • @Hacketo I have a problem to "refresh" the activity with the map :/ how can I do ?? – Pierpaolo Ercoli Sep 29 '14 at 14:07

1 Answers1

2

There's no need to schedule an update based on an Internet resource if you aren't connected to the Internet. The following snippet shows how to use the ConnectivityManager to query the active network and determine if it has Internet connectivity.

ConnectivityManager cm =
        (ConnectivityManager)context.getSystemService(Context.CONNECTIVITY_SERVICE);

NetworkInfo activeNetwork = cm.getActiveNetworkInfo();
boolean isConnected = activeNetwork != null &&
                      activeNetwork.isConnectedOrConnecting();

For Determining and Monitoring the Connectivity Status Help Link

Bhagirathsinh Gohil
  • 673
  • 1
  • 9
  • 25