android 3G 手机信号 信息获取.docx
- 文档编号:11718591
- 上传时间:2023-03-31
- 格式:DOCX
- 页数:12
- 大小:20.30KB
android 3G 手机信号 信息获取.docx
《android 3G 手机信号 信息获取.docx》由会员分享,可在线阅读,更多相关《android 3G 手机信号 信息获取.docx(12页珍藏版)》请在冰豆网上搜索。
android3G手机信号信息获取
android3G手机信号信息获取
分类:
android2012-09-2110:
591431人阅读评论(0)收藏举报
android手机servicelayout电信menu
在androi中手机信号信息的获取可以通过系统提供的TELEPHONY_SERVICE获取
[java]viewplaincopy
1TelephonyManagertel=(TelephonyManager)getSystemService(Context.TELEPHONY_SERVICE);
TelephonyManager可以监听PhoneStateListener,PhoneStateListener提供了
[java]viewplaincopy
2onSignalStrengthsChanged手机信号变动
3onServiceStateChanged手机服务状态变动
其中onSignalStrengthsChanged可以获取到的有用信息如下:
[java]viewplaincopy
4/*
5signalStrength.isGsm()是否GSM信号2Gor3G
6signalStrength.getCdmaDbm();联通3G信号强度
7signalStrength.getCdmaEcio();联通3G载干比
8signalStrength.getEvdoDbm();电信3G信号强度
9signalStrength.getEvdoEcio();电信3G载干比
10signalStrength.getEvdoSnr();电信3G信噪比
11signalStrength.getGsmSignalStrength();2G信号强度
12signalStrength.getGsmBitErrorRate();2G误码率
13
14载干比,它是指空中模拟电波中的信号与噪声的比值
15*/
奇怪的是移动的3G信号TD-SCDMA信息没办法获取到
而onServiceStateChanged提供的状态变动如下:
[java]viewplaincopy
16/*
17ServiceState.STATE_EMERGENCY_ONLY仅限紧急呼叫
18ServiceState.STATE_IN_SERVICE信号正常
19ServiceState.STATE_OUT_OF_SERVICE不在服务区
20ServiceState.STATE_POWER_OFF断电
21*/
以下给出具体的实例:
1.在布局文件中增加一个3G图标,和显示具体信息的文本(activity_g3_example.xml)
[html]viewplaincopy
22 android=" 23xmlns: tools=" 24android: layout_width="match_parent" 25android: layout_height="match_parent" 26android: gravity="center" 27android: orientation="vertical"> 28 29 30android: id="@+id/Icon_3GStatus" 31android: layout_width="wrap_content" 32android: layout_height="wrap_content" 33android: src="@drawable/ic_3g"/> 34 35 36android: id="@+id/Label_3GDetail" 37android: layout_width="wrap_content" 38android: layout_height="wrap_content" 39android: maxWidth="320dp"/> 40 41 2.为3G图标添加一组可选的图标,在drawable-hdpi目录下增加ic_3g.xml文件,内容如下: [html]viewplaincopy 42 xmlversion="1.0"encoding="utf-8"? > 43 44 android=" 45 maxLevel="60"android: drawable="@drawable/ic_3g_s3"/> 46 maxLevel="90"android: drawable="@drawable/ic_3g_s2"/> 47 maxLevel="96"android: drawable="@drawable/ic_3g_s1"/> 48 maxLevel="100"android: drawable="@drawable/ic_3g_s0"/> 49 注意需要导入用到的图片 3.在代码中监听手机信号和状态的变动(G3Example.java) [java]viewplaincopy 50packagecom.example.g3example; 51 52importandroid.os.Bundle; 53importandroid.app.Activity; 54importandroid.content.Context; 55importandroid.telephony.PhoneStateListener; 56importandroid.telephony.ServiceState; 57importandroid.telephony.SignalStrength; 58importandroid.telephony.TelephonyManager; 59importandroid.util.Log; 60importandroid.view.Menu; 61importandroid.widget.ImageButton; 62importandroid.widget.TextView; 63 64publicclassG3ExampleextendsActivity{ 65 66privatefinalStringTAG="G3Example"; 67 68privateImageButtonmIcon3G; 69privateTextViewmLabel3G; 70 71@Override 72publicvoidonCreate(BundlesavedInstanceState){ 73super.onCreate(savedInstanceState); 74setContentView(R.layout.activity_g3_example); 75 76mIcon3G=(ImageButton)findViewById(R.id.Icon_3GStatus); 77mLabel3G=(TextView)findViewById(R.id.Label_3GDetail); 78 79TelephonyManagertel=(TelephonyManager)getSystemService(Context.TELEPHONY_SERVICE); 80tel.listen(newPhoneStateMonitor(),PhoneStateListener.LISTEN_SIGNAL_STRENGTHS|PhoneStateListener.LISTEN_SERVICE_STATE); 81} 82 83@Override 84publicbooleanonCreateOptionsMenu(Menumenu){ 85getMenuInflater().inflate(R.menu.activity_g3_example,menu); 86returntrue; 87} 88 89publicclassPhoneStateMonitorextendsPhoneStateListener{ 90publicvoidonSignalStrengthsChanged(SignalStrengthsignalStrength){ 91super.onSignalStrengthsChanged(signalStrength); 92/* 93signalStrength.isGsm()是否GSM信号2Gor3G 94signalStrength.getCdmaDbm();联通3G信号强度 95signalStrength.getCdmaEcio();联通3G载干比 96signalStrength.getEvdoDbm();电信3G信号强度 97signalStrength.getEvdoEcio();电信3G载干比 98signalStrength.getEvdoSnr();电信3G信噪比 99signalStrength.getGsmSignalStrength();2G信号强度 100signalStrength.getGsmBitErrorRate();2G误码率 101 102载干比,它是指空中模拟电波中的信号与噪声的比值 103*/ 104mLabel3G.setText("IsGsm: "+signalStrength.isGsm()+ 105"\nCDMADbm: "+signalStrength.getCdmaDbm()+"Dbm"+ 106"\nCDMAEcio: "+signalStrength.getCdmaEcio()+"dB*10"+ 107"\nEvdoDbm: "+signalStrength.getEvdoDbm()+"Dbm"+ 108"\nEvdoEcio: "+signalStrength.getEvdoEcio()+"dB*10"+ 109"\nGsmSignalStrength: "+signalStrength.getGsmSignalStrength()+ 110"\nGsmBitErrorRate: "+signalStrength.getGsmBitErrorRate()); 111 112mIcon3G.setImageLevel(Math.abs(signalStrength.getGsmSignalStrength())); 113} 114 115publicvoidonServiceStateChanged(ServiceStateserviceState){ 116super.onServiceStateChanged(serviceState); 117 118/* 119ServiceState.STATE_EMERGENCY_ONLY仅限紧急呼叫 120ServiceState.STATE_IN_SERVICE信号正常 121ServiceState.STATE_OUT_OF_SERVICE不在服务区 122ServiceState.STATE_POWER_OFF断电 123*/ 124switch(serviceState.getState()) 125{ 126caseServiceState.STATE_EMERGENCY_ONLY: 127Log.d(TAG,"3GSTATUS: STATE_EMERGENCY_ONLY"); 128break; 129caseServiceState.STATE_IN_SERVICE: 130Log.d(TAG,"3GSTATUS: STATE_IN_SERVICE"); 131break; 132caseServiceState.STATE_OUT_OF_SERVICE: 133Log.d(TAG,"3GSTATUS: STATE_OUT_OF_SERVICE"); 134break; 135caseServiceState.STATE_POWER_OFF: 136Log.d(TAG,"3GSTATUS: STATE_POWER_OFF"); 137break; 138default: 139break; 140} 141} 142} 143} 4.最后在AndroidManifest.xml增加获取手机信号权限的支持 [html]viewplaincopy 144 name="android.permission.ACCESS_NETWORK_STATE"/> android3G手机信号信息获取 分类: android2012-09-2110: 591431人阅读评论(0)收藏举报 android手机servicelayout电信menu 在androi中手机信号信息的获取可以通过系统提供的TELEPHONY_SERVICE获取 [java]viewplaincopy 145TelephonyManagertel=(TelephonyManager)getSystemService(Context.TELEPHONY_SERVICE); TelephonyManager可以监听PhoneStateListener,PhoneStateListener提供了 [java]viewplaincopy 146onSignalStrengthsChanged手机信号变动 147onServiceStateChanged手机服务状态变动 其中onSignalStrengthsChanged可以获取到的有用信息如下: [java]viewplaincopy 148/* 149signalStrength.isGsm()是否GSM信号2Gor3G 150signalStrength.getCdmaDbm();联通3G信号强度 151signalStrength.getCdmaEcio();联通3G载干比 152signalStrength.getEvdoDbm();电信3G信号强度 153signalStrength.getEvdoEcio();电信3G载干比 154signalStrength.getEvdoSnr();电信3G信噪比 155signalStrength.getGsmSignalStrength();2G信号强度 156signalStrength.getGsmBitErrorRate();2G误码率 157 158载干比,它是指空中模拟电波中的信号与噪声的比值 159*/ 奇怪的是移动的3G信号TD-SCDMA信息没办法获取到 而onServiceStateChanged提供的状态变动如下: [java]viewplaincopy 160/* 161ServiceState.STATE_EMERGENCY_ONLY仅限紧急呼叫 162ServiceState.STATE_IN_SERVICE信号正常 163ServiceState.STATE_OUT_OF_SERVICE不在服务区 164ServiceState.STATE_POWER_OFF断电 165*/ 以下给出具体的实例: 1.在布局文件中增加一个3G图标,和显示具体信息的文本(activity_g3_example.xml) [html]viewplaincopy 166 android=" 167xmlns: tools=" 168android: layout_width="match_parent" 169android: layout_height="match_parent" 170android: gravity="center" 171android: orientation="vertical"> 172 173 174android: id="@+id/Icon_3GStatus" 175android: layout_width="wrap_content" 176android: layout_height="wrap_content" 177android: src="@drawable/ic_3g"/> 178 179 180android: id="@+id/Label_3GDetail" 181android: layout_width="wrap_content" 182android: layout_height="wrap_content" 183android: maxWidth="320dp"/> 184 185 2.为3G图标添加一组可选的图标,在drawable-hdpi目录下增加ic_3g.xml文件,内容如下: [html]viewplaincopy 186 xmlversion="1.0"encoding="utf-8"? > 187 188 android=" 189 maxLevel="60"android: drawable="@drawable/ic_3g_s3"/> 190 maxLevel="90"android: drawable="@drawable/ic_3g_s2"/> 191 maxLevel="96"android: drawable="@drawable/ic_3g_s1"/> 192 maxLevel="100"android: drawable="@drawable/ic_3g_s0"/> 193 注意需要导入用到的图片 3.在代码中监听手机信号和状态的变动(G3Example.java) [java]viewplaincopy 194packagecom.example.g3example; 195 196importandroid.os.Bundle; 197importandroid.app.Activity; 198importandroid.content.Context; 199importandroid.telephony.PhoneStateListener; 200importandroid.telephony.ServiceState; 201importandroid.telephony.SignalStrength; 202importandroid.telephony.TelephonyManager; 203importandroid.util.Log; 204importandroid.view.Menu; 205importandroid.widget.ImageButton; 206importandroid.widget.TextView; 207 208publicclassG3ExampleextendsActivity{ 209 210privatefinalStringTAG="G3Example"; 211 212privateImageButtonmIcon3G; 213privateTextViewmLabel3G; 214 215@Override 216publicvoidonCreate(BundlesavedInstanceState){ 217super.onCreate(savedInstanceState); 218setContentView(R.layout.activity_g3_example); 219 220mIcon3G=(ImageButton)findViewById(R.id.Icon_3GStatus); 221mLabel3G=(TextView)findViewById(R.id.Label_3GDetail); 222 223TelephonyManagertel=(TelephonyManager)getSystemService(Context.TELEPHONY_SERVICE); 224tel.listen(newPhoneStateMonitor(),PhoneStateListener.LISTEN_SIGNAL_STRENGTHS|PhoneStateListener.LISTEN_SERVICE_STATE); 225}
- 配套讲稿:
如PPT文件的首页显示word图标,表示该PPT已包含配套word讲稿。双击word图标可打开word文档。
- 特殊限制:
部分文档作品中含有的国旗、国徽等图片,仅作为作品整体效果示例展示,禁止商用。设计者仅对作品中独创性部分享有著作权。
- 关 键 词:
- android 3G 手机信号 信息获取 信息 获取
![提示](https://static.bdocx.com/images/bang_tan.gif)