2

我编写了一段 Android 代码,它通过回调注册 aPhoneStateListener并在发生变化时报告 GSM 信号强度值 。onSignalStrengthsChanged一切正常,但我想在第一次更改发生之前获得初始信号强度。有没有办法在方法结束之前找出 GSM 信号强度onCreate(参见代码末尾的注释行)?

这是我的代码:

public class MainActivity extends Activity {

private int mStrength;
private PhoneStateListener phoneStateListener;
private TelephonyManager telephonyManager;

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    phoneStateListener = new PhoneStateListener() {
        @Override
        public void onSignalStrengthsChanged(SignalStrength signalStrength){
             super.onSignalStrengthsChanged(signalStrength);
             int currStrength = signalStrength.getGsmSignalStrength();
             mStrength = currStrength;

             Toast.makeText(getApplicationContext(),
                          "signal:" + String.valueOf(mStrength),
                          Toast.LENGTH_SHORT).show();
        }               
    };

    telephonyManager = (TelephonyManager)getSystemService(Context.TELEPHONY_SERVICE);
    telephonyManager.listen(phoneStateListener,
               PhoneStateListener.LISTEN_SIGNAL_STRENGTHS);

    // What is value of GSM signal here? ...
    // Log.d("SignalStrength:", "??");

}

}
4

1 回答 1

0

不能使用API 级别 7 中添加的SignalStrength 类吗?

于 2013-06-05T08:06:44.917 回答