2
我想在android設備上點擊任何按鈕即可獲取當前信號強度。
我寫了這個獲取當前SignalStrengths android
public static int getSignal(Context c) {
class MyPhoneStateListener extends PhoneStateListener {
int signal;
@Override
public void onSignalStrengthsChanged(SignalStrength signalStrength) {
super.onSignalStrengthsChanged(signalStrength);
signal = signalStrength.getGsmSignalStrength();
}
}
TelephonyManager Tel;
MyPhoneStateListener MyListener;
MyListener = new MyPhoneStateListener();
Tel = (TelephonyManager) c.getSystemService(Context.TELEPHONY_SERVICE);
Tel.listen(MyListener, PhoneStateListener.LISTEN_SIGNAL_STRENGTHS);
Tel.listen(MyListener, PhoneStateListener.LISTEN_NONE);
return MyListener.signal;
}
代碼,但它總是返回我0
請有人告訴我如何獲取當前信號強度。
目前無法獲得當前的信號強度?如果我不想等待不確定的時間等待onSignalStrengthsChanged()做些什麼? – 2011-06-17 00:50:40
請問如果你找到解決方案告訴我? – Piraba 2011-08-01 12:47:31
嗯 - 詳細[這裏](http://stackoverflow.com/a/3889407/281545)註冊PhoneStateListener後,您將有即時通知。仍然你的答案[應該是有效的](http://stackoverflow.com/questions/3888775/instant-signal-strength/3889407#comment4143475_3890419) – 2013-07-08 17:35:42