0

I have an audio stream playing but want to constantly check if the persons internet connection dropped- and if so- restart the audio stream or at least notify them why it stopped.

I checked the onError for mediaplayer but it doesn't get triggered when internet drops-

I have code to check for an internet connection- but is there a way to run this in the background every minute or so? (when phone goes into standby as well)

public boolean isOnline() {
    ConnectivityManager cm = (ConnectivityManager) getSystemService(Context.CONNECTIVITY_SERVICE);
    NetworkInfo netInfo = cm.getActiveNetworkInfo();
    if (netInfo != null && netInfo.isConnected()) {
        return true;
    }
    return false;
}

Thanks in advance,

user3267847
  • 143
  • 1
  • 10

1 Answers1

0

Sure. You can use a runnable, which would be called however often you need it to.

If you want to be efficient though, I would look for an internet listener. Unfamiliar with the topic myself, but some quick searching produced this.

Hope this helps.

Community
  • 1
  • 1
Sipty
  • 1,159
  • 1
  • 10
  • 18
  • 1
    doesn't a runnable stop when the phone goes into standby though? – user3267847 Aug 07 '15 at 16:04
  • Ah, I missed that part! Yes, it does. You will need to implement a service in that case. In that case, please have a look at this tutorial, which helped me at the time: http://www.vogella.com/articles/AndroidServices/article.html – Sipty Aug 07 '15 at 16:09
  • yah I tried the receiver for the listener- but unfortunately that only monitors when the connection changes, not actually drops. – user3267847 Aug 07 '15 at 16:15
  • Gotcha- will check on that- Thank you – user3267847 Aug 07 '15 at 16:15