Robert Smith
Robert Smith

Reputation: 457

Checking internet connection as relentless service in android

I am developing an application, where there is a need to check internet connection availability as a continuous procees as long as the whole application is running and destroy when application is not in use.

The process should notify me, if internet connection is in reach or gone on internet connection availability. On it's notification, I will do some task, both for if not available or available.

Upvotes: 2

Views: 628

Answers (1)

Phil
Phil

Reputation: 36289

You can create a BroadCastReceiver to listen for network changes, then use the ConnectivityManager to check if the connection has been lost.

You will need to add these lines in your AndroidManifest (replacing MyClassName with the name of your class, just as you would do for any Activity declared in the AndroidManifest:

<receiver android:name=".MyClassName">
       <intent-filter>
          <action android:name="android.net.conn.CONNECTIVITY_CHANGE"/>
       </intent-filter>
</receiver>

Upvotes: 1

Related Questions