Hello everyone,
I'm trying to get strength of current signal in GSM networks, tried to code
it by myself, then looked at some tutorial, but still can't get it to work.
Here is what I have right now.
public class TestActivity extends Activity{
private MyPhoneStateListener m_psl;
private TelephonyManager m_tm;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
m_tm = (TelephonyManager) getSystemService(TELEPHONY_SERVICE);
m_psl = new MyPhoneStateListener();
m_tm.listen(m_psl, PhoneStateListener.LISTEN_SIGNAL_STRENGTHS);
m_tm.listen(m_psl, PhoneStateListener.LISTEN_CELL_LOCATION);
}
@Override
protected void onDestroy() {
super.onDestroy();
m_tm.listen(m_psl, PhoneStateListener.LISTEN_NONE);
}
@Override
protected void onPause() {
super.onPause();
m_tm.listen(m_psl, PhoneStateListener.LISTEN_NONE);
}
@Override
protected void onResume() {
super.onResume();
m_tm.listen(m_psl, PhoneStateListener.LISTEN_SIGNAL_STRENGTHS);
m_tm.listen(m_psl, PhoneStateListener.LISTEN_CELL_LOCATION);
}
private class MyPhoneStateListener extends PhoneStateListener{
@Override
public void onSignalStrengthsChanged(SignalStrength
signalStrength){
super.onSignalStrengthsChanged(signalStrength);
Toast.makeText(getApplicationContext(), "Signal strength is
now "+signalStrength.getGsmSignalStrength(), Toast.LENGTH_SHORT).show();
}
@Override
public void onCellLocationChanged(CellLocation location) {
super.onCellLocationChanged(location);
Toast.makeText(getApplicationContext(), "Current cell
location changed", Toast.LENGTH_SHORT).show();
}
};
}
Tried on on Nexus One 2.1 and 2.2 and I still get the signal strength toast
only when I start/resume the application. When the application is running, I
receive onCellLocationChanged toasts while I move around, which is fine and
how it's suppose to be, but the signal strength toast is not showing even
when I see the signal strength changing in the task bar. I know this is a
common goal so I suppose there must be some mistake in my code or some way
to achieve this.
Thanks for all your replies.
Best regards,
Filip Havlicek
--
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en