How to get cell service signal strength in Android? How to get cell service signal strength in Android? android android

How to get cell service signal strength in Android?


create a PhoneStateListener and handle the onSignalStrengthChanged callback. When your app is initialized, it should give you an initial notification. This is in 1.x. in 2.x, there's an open issue about this.


This code may help:

PhoneStateListener phoneStateListener = new PhoneStateListener() {public void onCallForwardingIndicatorChanged(boolean cfi) {}public void onCallStateChanged(int state, String incomingNumber) {}public void onCellLocationChanged(CellLocation location) {}public void onDataActivity(int direction) {}public void onDataConnectionStateChanged(int state) {}public void onMessageWaitingIndicatorChanged(boolean mwi) {}public void onServiceStateChanged(ServiceState serviceState) {}public void onSignalStrengthChanged(int asu) {}};

Once you’ve created your own Phone State Listener, register it with the Telephony Manager using a bitmask to indicate the events you want to listen for, as shown in the following code snippet:

TelephonyManager telephonyManager = (TelephonyManager) this.getSystemService(Context.TELEPHONY_SERVICE);telephonyManager.listen(phoneStateListener,PhoneStateListener.LISTEN_CALL_FORWARDING_INDICATOR |PhoneStateListener.LISTEN_CALL_STATE |PhoneStateListener.LISTEN_CELL_LOCATION |PhoneStateListener.LISTEN_DATA_ACTIVITY |PhoneStateListener.LISTEN_DATA_CONNECTION_STATE |PhoneStateListener.LISTEN_MESSAGE_WAITING_INDICATOR |PhoneStateListener.LISTEN_SERVICE_STATE |PhoneStateListener.LISTEN_SIGNAL_STRENGTH);

Also, need to add these to AndroidManifest.xml:

<uses-permission android:name="android.permission.READ_PHONE_STATE"/><uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION"/>