Showing posts with label Android TelephonyManager. Show all posts
Showing posts with label Android TelephonyManager. Show all posts

Wednesday, November 5, 2014

Android Listen to Network State Change


Instagram This will help you to detect network changing states in android phone. For get an idea abut the API use for this read Followings.

Following Steps will do it. After setup the code and run the app just change your network status to flight mode and then again revert.


First we need to add required permission to read the changes of network connectivity. Insert following line in you AndroidManifest.xml file to do that.



       <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
       <uses-permission android:name="android.permission.READ_PHONE_STATE"/>
Now you good to go with the creating of your service.
Following is the code for the service that will detect the changes of network. (You can start  this even as BroadcastReceiver) 

Get an idea about Services Vs BroadcastReceivers in android.