In wireless telephony, a cell is the geographical area covered by a cellular telephone transmitter.
A mobile devices keeps changing its Cell in order to stay connected to the network provider. That is how you get uninterrupted network access wherever you go. Using PhoneStateListener class in Android, we can determine if user’s device switches Cell Tower.
[From official docs] PhoneStateListener is a listener class for monitoring changes in specific telephony states on the device, including service state, signal strength, message waiting indicator (voicemail), and others.
Note that access to some telephony information is permission-protected. Your application won’t receive updates for protected information unless it has the appropriate permissions declared in its manifest file.
- Since detecting cell location change in Android requires some Location Tracking, add the following permission in your manifest : <uses-permission android:name=”android.permission.ACCESS_COARSE_LOCATION” />.
- Create a class that extends PhoneStateListener and override the onCellLocationChanged method :
- Get Android’s Telephony Manager System Service and set up a listener for getting Cell Tower Location changes. Pass it an object of the class extending PhoneStateListener that you created earlier.
- Now, you’ll receive and CellLocation object whenever the user’s device switches Cell Tower. Using this object you can request a location update by calling requestLocationUpdate().