代码是网上找的,但是真机测试信号一直是99,不知道是什么原因,求大神解答
package com.signal.testintensity;
import android.app.Activity;
import android.content.Context;
import android.os.Bundle;
import android.telephony.PhoneStateListener;
import android.telephony.SignalStrength;
import android.telephony.TelephonyManager;
import android.widget.Toast;
public class MainActivity extends Activity{
/* 这个变量需要是全球性的,所以我们可以用它们onResume和onPause方法停止听众*/
TelephonyManager Tel;
MyPhoneStateListener MyListener;
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState){
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
/* 更新的听众,并且启动它*/
MyListener = new MyPhoneStateListener();
Tel = ( TelephonyManager )getSystemService(Context.TELEPHONY_SERVICE);
Tel.listen(MyListener ,PhoneStateListener.LISTEN_SIGNAL_STRENGTHS);
}
/* 当应用程序被称为被最小化*/
@Override
protected void onPause(){
super.onPause();
Tel.listen(MyListener, PhoneStateListener.LISTEN_SIGNAL_STRENGTHS);
}
/* Called when the application resumes */
@Override
protected void onResume(){
super.onResume();
Tel.listen(MyListener,PhoneStateListener.LISTEN_SIGNAL_STRENGTHS);
}
private class MyPhoneStateListener extends PhoneStateListener{
/*得到信号的强度由每个tiome供应商,有更新*/
@Override
public void onSignalStrengthsChanged(SignalStrength signalStrength){
super.onSignalStrengthsChanged(signalStrength);
Toast.makeText(getApplicationContext(), String.valueOf(signalStrength.getGsmSignalStrength()), Toast.LENGTH_SHORT).show();
}
};
}
package com.signal.testintensity;
import android.app.Activity;
import android.content.Context;
import android.os.Bundle;
import android.telephony.PhoneStateListener;
import android.telephony.SignalStrength;
import android.telephony.TelephonyManager;
import android.widget.Toast;
public class MainActivity extends Activity{
/* 这个变量需要是全球性的,所以我们可以用它们onResume和onPause方法停止听众*/
TelephonyManager Tel;
MyPhoneStateListener MyListener;
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState){
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
/* 更新的听众,并且启动它*/
MyListener = new MyPhoneStateListener();
Tel = ( TelephonyManager )getSystemService(Context.TELEPHONY_SERVICE);
Tel.listen(MyListener ,PhoneStateListener.LISTEN_SIGNAL_STRENGTHS);
}
/* 当应用程序被称为被最小化*/
@Override
protected void onPause(){
super.onPause();
Tel.listen(MyListener, PhoneStateListener.LISTEN_SIGNAL_STRENGTHS);
}
/* Called when the application resumes */
@Override
protected void onResume(){
super.onResume();
Tel.listen(MyListener,PhoneStateListener.LISTEN_SIGNAL_STRENGTHS);
}
private class MyPhoneStateListener extends PhoneStateListener{
/*得到信号的强度由每个tiome供应商,有更新*/
@Override
public void onSignalStrengthsChanged(SignalStrength signalStrength){
super.onSignalStrengthsChanged(signalStrength);
Toast.makeText(getApplicationContext(), String.valueOf(signalStrength.getGsmSignalStrength()), Toast.LENGTH_SHORT).show();
}
};
}