我想知道我目前在
Android上的手机信号塔的信号强度.经过一些研究后我发现,我应该使用一个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(值)就想停止听众
任何的想法 ?
谢谢