I am trying to show the current signal strength and current cell ID and Lac in my application for 3g network. Since it has to be compatible for API-8, I am using SignalStrength class from android.telephony. When I click a button, for now I want it to show the CID, Lac and signal strength of current cell. I am getting the CID and lac but the signal strength is always showing 0. The code is given below:
public void onClick(View v) {
switch (v.getId()) {
case R.id.bShowCell:
GsmCellLocation location;
String cellID = "";
String lac = "";
Context context = (Context) getApplicationContext();
TelephonyManager tm = (TelephonyManager) context
.getSystemService(Context.TELEPHONY_SERVICE);
location = (GsmCellLocation) tm.getCellLocation();
cellID = String.valueOf(location.getCid());
lac = String.valueOf(location.getLac());
CurCell.setText(cellID);
CellLac.setText(lac);
CurStrgth.setText(getRSSI());
}
}
public String getRSSI() {
MyListener = new MyPhoneStateListener();
Tel = (TelephonyManager) getSystemService(Context.TELEPHONY_SERVICE);
Tel.listen(MyListener, PhoneStateListener.LISTEN_SIGNAL_STRENGTHS);
String strength = MyListener.getStrength();
return strength;
}
class MyPhoneStateListener extends PhoneStateListener {
public int singalStrengths;
@Override
public void onSignalStrengthsChanged(SignalStrength signalStrength) {
super.onSignalStrengthsChanged(signalStrength);
int asu = signalStrength.getGsmSignalStrength();
singalStrengths = -113 + 2 * asu;
}
public String getStrength() {
return String.valueOf(singalStrengths);
}
}
I have checked many examples online and I think my code is okay. But when I checked it in debug mode, I see that when I click the button, the program never goes in onSignalStrengthsChanged. Is there anything I am missing?