请教: android 如何获取手机的当前信号强度 本帖最后由 xingao0113 于 2010-01-21 12:24:04 编辑 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 电池状态可以监听ACTION_BATTERY_CHANGED广播,但是信号状态貌似没有相应广播 http://bbs.android123.com/thread-4018-1-1.html package lab.sodino.singal;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.ScrollView;import android.widget.Scroller;import android.widget.TextView;import android.widget.Toast;public class SingalAct extends Activity { private TextView textView; private TelephonyManager telMag; private MyPhoneStateListener phoneLis; /** Called when the activity is first created. */ @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); textView = new TextView(this); textView.setText("start...\n"); ScrollView scrollView = new ScrollView(this); scrollView.addView(textView); setContentView(scrollView); phoneLis = new MyPhoneStateListener(); telMag = (TelephonyManager) getSystemService(Context.TELEPHONY_SERVICE); telMag.listen(phoneLis, PhoneStateListener.LISTEN_SIGNAL_STRENGTHS); textView.append("NetworkCountryIso=" + telMag.getNetworkCountryIso() + "\n"); textView .append("NetworkOperator=" + telMag.getNetworkOperator() + "\n"); textView.append("NetworkOperatorName=" + telMag.getNetworkOperatorName() + "\n"); textView.append("NetworkType=" + telMag.getNetworkType() + "\n"); } public void onPause() { super.onPause(); telMag.listen(phoneLis, PhoneStateListener.LISTEN_SIGNAL_STRENGTHS); } public void onResume() { super.onResume(); telMag.listen(phoneLis, PhoneStateListener.LISTEN_SIGNAL_STRENGTHS); } private class MyPhoneStateListener extends PhoneStateListener { private int lastStrength = 0; public void onSignalStrengthsChanged(SignalStrength signalStrength) { super.onSignalStrengthsChanged(signalStrength); lastStrength = signalStrength.getGsmSignalStrength(); textView.append("SignalQuality=" + lastStrength + "\n"); } /** 获取上一次变化到现在的信号强度值。 */ public int getLastStrength() { return lastStrength; } }}主动获取调用:getLastStrength()这也是一个折中的方法吧 求一些消息推送机制或者那些提供这些服务的软件/公司?収不收费无关系。 Android应用程序意外终止 作为Android手机的服务器,如何选择? 关于前置摄像头的问题 如何将一个AnimationDrawable画到一张View中? 布局中ListView不断响应onScroll事件问题 android spinner sqlite 初始化的问题!什么时候创建据库文件? JNI不懂 Android app如何通过内部链接打开天猫的商品详情页面 android 锁屏 popupwindow上控件怎么像在activity上一样有按键响应?
import android.content.Context;
import android.os.Bundle;
import android.telephony.PhoneStateListener;
import android.telephony.SignalStrength;
import android.telephony.TelephonyManager;
import android.widget.ScrollView;
import android.widget.Scroller;
import android.widget.TextView;
import android.widget.Toast;public class SingalAct extends Activity {
private TextView textView;
private TelephonyManager telMag;
private MyPhoneStateListener phoneLis; /** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
textView = new TextView(this);
textView.setText("start...\n");
ScrollView scrollView = new ScrollView(this);
scrollView.addView(textView);
setContentView(scrollView);
phoneLis = new MyPhoneStateListener();
telMag = (TelephonyManager) getSystemService(Context.TELEPHONY_SERVICE);
telMag.listen(phoneLis, PhoneStateListener.LISTEN_SIGNAL_STRENGTHS);
textView.append("NetworkCountryIso=" + telMag.getNetworkCountryIso()
+ "\n");
textView
.append("NetworkOperator=" + telMag.getNetworkOperator() + "\n");
textView.append("NetworkOperatorName="
+ telMag.getNetworkOperatorName() + "\n");
textView.append("NetworkType=" + telMag.getNetworkType() + "\n");
} public void onPause() {
super.onPause();
telMag.listen(phoneLis, PhoneStateListener.LISTEN_SIGNAL_STRENGTHS);
} public void onResume() {
super.onResume();
telMag.listen(phoneLis, PhoneStateListener.LISTEN_SIGNAL_STRENGTHS);
} private class MyPhoneStateListener extends PhoneStateListener {
private int lastStrength = 0; public void onSignalStrengthsChanged(SignalStrength signalStrength) {
super.onSignalStrengthsChanged(signalStrength);
lastStrength = signalStrength.getGsmSignalStrength();
textView.append("SignalQuality=" + lastStrength + "\n");
} /** 获取上一次变化到现在的信号强度值。 */
public int getLastStrength() {
return lastStrength;
}
}
}
主动获取调用:getLastStrength()这也是一个折中的方法吧