首页新闻找找看学习计划

android获取基站信号强度问题?

0
悬赏园豆:100 [已解决问题] 解决于 2016-11-03 11:34
 1 public class MainActivity extends AppCompatActivity {
 2  
 3     TelephonyManager telephonyManager;
 4     MyPhoneStateListener MyListener;
 5     @Override
 6     public void onCreate(Bundle savedInstanceState) {
 7         super.onCreate(savedInstanceState);
 8         setContentView(R.layout.activity_main);
 9         final TextView textView1 = (TextView) findViewById(R.id.text1);
10         final TextView textView2 = (TextView) findViewById(R.id.text2);
11         Button button= (Button) findViewById(R.id.button1);
12          telephonyManager= (TelephonyManager) MainActivity.this.getSystemService(Context.TELEPHONY_SERVICE);
13         MyListener = new MyPhoneStateListener();
14         button.setOnClickListener(new View.OnClickListener() {
15             @Override
16             public void onClick(View v) {
17 
18                 String operator = telephonyManager.getNetworkOperator();
19                 /**通过operator获取 MCC 和MNC */
20                 int mcc = Integer.parseInt(operator.substring(0, 3));
21                 int mnc = Integer.parseInt(operator.substring(3));
22                 GsmCellLocation location = (GsmCellLocation) telephonyManager.getCellLocation();
23                 /**通过GsmCellLocation获取中国移动和联通 LAC 和cellID */
24                 int lac = location.getLac();
25                 int cellid = location.getCid();
26                 System.out.println("**"+mcc+"A"+mnc+"A"+lac+"A"+cellid);
27                 textView1.setText("国家编号:"+mcc+"运营商编号:"+mnc+"LAC:"+lac+"CellID:"+cellid);
28                 List<CellInfo> infos = telephonyManager.getAllCellInfo();
29                 // List<NeighboringCellInfo> infos = telephonyManager.getNeighboringCellInfo();
30                 StringBuffer sb = new StringBuffer("总数 : " + infos.size() + "\n");
31                 for (CellInfo info1 : infos) { // 根据邻区总数进行循环
32                     //  sb.append(" LAC : " + info1.getLac()); // 取出当前邻区的LAC
33                     //  sb.append(" CID : " + info1.getCid()); // 取出当前邻区的CID
34                     sb.append(" CID : " + info1.toString()); // 取出当前邻区的CID
35                     //  sb.append(" BSSS : " + (-113 + 2 * info1.getRssi()) + "\n"); // 获取邻区基站信号强度
36                 }
37 
38                 Log.i(TAG, " 获取邻区基站信息:" + sb.toString());
39                 textView2.setText(sb.toString());
40             }
41         });
42         telephonyManager.listen(MyListener, PhoneStateListener.LISTEN_SIGNAL_STRENGTHS);
43        // telephonyManager.listen(celllistener, PhoneStateListener.LISTEN_CELL_LOCATION); // 基站位置的变化
44     }
45 
46 
47 
48     private class MyPhoneStateListener extends PhoneStateListener
49     {
50         /* Get the Signal strength from the provider, each tiome there is an update  从得到的信号强度,每个tiome供应商有更新*/
51         @Override
52 
53         public void onSignalStrengthsChanged(SignalStrength signalStrength)
54         {
55             super.onSignalStrengthsChanged(signalStrength);
56             if (signalStrength.getGsmSignalStrength() != 99) {
57                 Toast.makeText(getApplicationContext(),
58                         "Go to Firstdroid!!! GSM Cinr = " + String.valueOf(signalStrength.getGsmSignalStrength() * 2 - 113) + "dbM", Toast.LENGTH_SHORT).show();
59 
60 
61                 System.out.println("****" + String.valueOf(signalStrength.getGsmSignalStrength() * 2 - 113));
62             }
63         }
64     }

1.  57行代码,Toast的数据是基站信号强度吗?还是手机信号强度?手机信号强度和基站信号强度一样吗?

2.  61行打印的数据 CellInfoGsm:{mRegistered=YES mTimeStampType=oem_ril mTimeStamp=327578425571078ns CellIdentityGsm:{ mMcc=460 mMnc=0 mLac=20978 mCid=64749} CellSignalStrengthGsm: ss=22 ber=99}

  ss和ber是什么意思啊?

 

3.  29行 // List<NeighboringCellInfo> infos = telephonyManager.getNeighboringCellInfo();  infos.size 一直为0,求助

咖喱不见不散啊的主页 咖喱不见不散啊 | 初学一级 | 园豆:122
提问于:2016-09-07 15:50
< >
分享
最佳答案
0

  真不给力啊

咖喱不见不散啊 | 初学一级 |园豆:122 | 2016-11-03 11:34
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册