Created
August 2, 2018 04:17
-
-
Save sud007/945a7bf8b07bdc0e30261f5805ad540a to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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