Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
PhoneStateListener phoneListener;
private void setupSignalStrength() {
final TelephonyManager manager = (TelephonyManager) getSystemService(Context.TELEPHONY_SERVICE);
phoneListener = new PhoneStateListener() {
@Override
public void onSignalStrengthsChanged(SignalStrength signalStrength) {
if (manager.getNetworkOperator().equals("")) {
} else {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
// See https://github.com/AlstonLin/TheLearningLock/issues/54
Log.d("SIGNAL",""+signalStrength.getLevel());
} else {
// Just show the full icon
Log.d("SIGNAL",""+signalStrength.getGsmSignalStrength());
}
}
}
@Override
public void onCellInfoChanged(List<CellInfo> cellInfo) {
super.onCellInfoChanged(cellInfo);
for (CellInfo info : cellInfo) {
Log.d("SIGNAL",""+info.toString());
}
}
};
manager.listen(phoneListener, PhoneStateListener.LISTEN_SIGNAL_STRENGTHS);
}
Permissions required for Telephony Manager :
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
<uses-permission android:name="android.permission.CHANGE_NETWORK_STATE"/>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.