我想知道在安卓系统下当前基站的信号强度。经过一些研究,我发现应该使用PhoneStateListener
监听更新以获取值(我认为这是奇怪的方法)。
所以我想要在收到信号后立即停止监听器。以下是我使用的代码:
// object containing the information about the cell
MyGSMCell myGSMCell = new MyGSMCell(cid,lac);
// object listening for the signal strength
new GetGsmSignalStrength(myGSMCell, context);
...
public class GetGsmSignalStrength {
private MyGSMCell callback;
private TelephonyManager telMan;
private MyPhoneStateListener myListener;
public GetGsmSignalStrength(MyGSMCell callback, Context context) {
this.callback = callback;
this.myListener = new MyPhoneStateListener();
this.telMan = (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE);
this.telMan.listen(this.myListener, PhoneStateListener.LISTEN_SIGNAL_STRENGTHS);
}
private class MyPhoneStateListener extends PhoneStateListener
{
public void onSignalStrengthsChanged(SignalStrength signalStrength)
{
// get the strength
super.onSignalStrengthsChanged(signalStrength);
// return it to the MyGSMCell object to set the value
callback.setStrength(signalStrength.getGsmSignalStrength());
}
}
}
我希望在发送
setStrength(value)
后立即停止监听器。有什么想法吗?
谢谢。