galibujianbusana 2016-09-07 07:24 采纳率: 0%
浏览 4947

android获取基站信号强度?

1.这个方法中toast的是基站信号强度吗?手机上面显示的信号强度和基站信号强度一样吗?
想获得连接基站的信号强度这样写对吗?
2.下面代码打印时输出结果:CellInfoGsm:{mRegistered=YES mTimeStampType=oem_ril mTimeStamp=327578425571078ns CellIdentityGsm:{ mMcc=460 mMnc=0 mLac=20978 mCid=64749} CellSignalStrengthGsm: ss=22 ber=99}
这里的ss,和ber是什么意思啊?

  1. List infos = telephonyManager.getAllCellInfo(); // List infos = telephonyManager.getNeighboringCellInfo();这个不能用了,返回值一直是infos.size为0,求助 ```
 private class MyPhoneStateListener extends PhoneStateListener
    {
        /* Get the Signal strength from the provider, each tiome there is an update  从得到的信号强度,每个tiome供应商有更新*/
        @Override

        public void onSignalStrengthsChanged(SignalStrength signalStrength)
        {
            super.onSignalStrengthsChanged(signalStrength);
            if (signalStrength.getGsmSignalStrength() != 99) {
                Toast.makeText(getApplicationContext(),
                        "Go to Firstdroid!!! GSM Cinr = " + String.valueOf(signalStrength.getGsmSignalStrength() * 2 - 113) + "dbM", Toast.LENGTH_SHORT).show();
                System.out.println("****" + String.valueOf(signalStrength.getGsmSignalStrength() * 2 - 113));
            }
        }
    }

代码:

public class MainActivity extends AppCompatActivity {
    private static final String TAG = "GSMCellLocationActivity";
    TelephonyManager telephonyManager;
    MyPhoneStateListener MyListener;
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        final TextView textView1 = (TextView) findViewById(R.id.text1);
        final TextView textView2 = (TextView) findViewById(R.id.text2);
        Button button= (Button) findViewById(R.id.button1);
         telephonyManager= (TelephonyManager) MainActivity.this.getSystemService(Context.TELEPHONY_SERVICE);
        MyListener = new MyPhoneStateListener();
        button.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {

                String operator = telephonyManager.getNetworkOperator();
                /**通过operator获取 MCC 和MNC */
                int mcc = Integer.parseInt(operator.substring(0, 3));
                int mnc = Integer.parseInt(operator.substring(3));
                GsmCellLocation location = (GsmCellLocation) telephonyManager.getCellLocation();
                /**通过GsmCellLocation获取中国移动和联通 LAC 和cellID */
                int lac = location.getLac();
                int cellid = location.getCid();
                System.out.println("**"+mcc+"A"+mnc+"A"+lac+"A"+cellid);
                textView1.setText("国家编号:"+mcc+"运营商编号:"+mnc+"LAC:"+lac+"CellID:"+cellid);
                List<CellInfo> infos = telephonyManager.getAllCellInfo();
                // List<NeighboringCellInfo> infos = telephonyManager.getNeighboringCellInfo();
                StringBuffer sb = new StringBuffer("总数 : " + infos.size() + "\n");
                for (CellInfo info1 : infos) { // 根据邻区总数进行循环
                    //  sb.append(" LAC : " + info1.getLac()); // 取出当前邻区的LAC
                    //  sb.append(" CID : " + info1.getCid()); // 取出当前邻区的CID
                    sb.append(" CID : " + info1.toString()); // 取出当前邻区的CID
                    //  sb.append(" BSSS : " + (-113 + 2 * info1.getRssi()) + "\n"); // 获取邻区基站信号强度
                }

                Log.i(TAG, " 获取邻区基站信息:" + sb.toString());
                textView2.setText(sb.toString());
            }
        });
        telephonyManager.listen(MyListener, PhoneStateListener.LISTEN_SIGNAL_STRENGTHS);
       // telephonyManager.listen(celllistener, PhoneStateListener.LISTEN_CELL_LOCATION); // 基站位置的变化
    }



    private class MyPhoneStateListener extends PhoneStateListener
    {
        /* Get the Signal strength from the provider, each tiome there is an update  从得到的信号强度,每个tiome供应商有更新*/
        @Override

        public void onSignalStrengthsChanged(SignalStrength signalStrength)
        {
            super.onSignalStrengthsChanged(signalStrength);
            if (signalStrength.getGsmSignalStrength() != 99) {
                Toast.makeText(getApplicationContext(),
                        "Go to Firstdroid!!! GSM Cinr = " + String.valueOf(signalStrength.getGsmSignalStrength() * 2 - 113) + "dbM", Toast.LENGTH_SHORT).show();
                System.out.println("****" + String.valueOf(signalStrength.getGsmSignalStrength() * 2 - 113));
            }
        }
    }







  • 写回答

1条回答

  • zqbnqsdsmd 2016-11-15 18:27
    关注
    评论

报告相同问题?

悬赏问题

  • ¥15 运筹学排序问题中的在线排序
  • ¥15 关于docker部署flink集成hadoop的yarn,请教个问题 flink启动yarn-session.sh连不上hadoop,这个整了好几天一直不行,求帮忙看一下怎么解决
  • ¥30 求一段fortran代码用IVF编译运行的结果
  • ¥15 深度学习根据CNN网络模型,搭建BP模型并训练MNIST数据集
  • ¥15 C++ 头文件/宏冲突问题解决
  • ¥15 用comsol模拟大气湍流通过底部加热(温度不同)的腔体
  • ¥50 安卓adb backup备份子用户应用数据失败
  • ¥20 有人能用聚类分析帮我分析一下文本内容嘛
  • ¥30 python代码,帮调试,帮帮忙吧
  • ¥15 #MATLAB仿真#车辆换道路径规划