Tôi muốn biết cường độ tín hiệu của tháp di động hiện tại của mình trên Android. Sau khi một số nghiên cứu tôi tìm thấy, rằng tôi nên sử dụng một PhoneStateListener
mà lắng nghe cho một bản cập nhật để có được giá trị (cách kỳ lạ để làm điều đó IMHO).Dừng trình nghe sau khi cập nhật lần đầu
Vì vậy, tôi muốn nhận được tín hiệu ngay sau khi tôi nhận được tín hiệu và ngừng người nghe sau đó. Đây là code tôi sử dụng:
// 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());
}
}
}
Tôi muốn dừng lại người nghe ngay sau khi tôi gửi một setStrength(value)
Bất kỳ ý tưởng?
Cảm ơn bạn
trình tốt, nhờ –