安卓:得到的CellID和RSS基站和Neigboring细胞 [英] Android: get CellID and RSS for Base Station and Neigboring Cells

查看:432
本文介绍了安卓:得到的CellID和RSS基站和Neigboring细胞的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图得到以下数据:

  • 基站:的CellID和RSS(识别哪一个是基站)
  • 对于所有neigbouring站:的CellID和RSS

有各种API,它看起来像我不得不使用不同的API telephonyManager和PhoneStateListener。我是一个littlebit困惑,因为我认为这应该是提供一个接口。此外,我认为这应该是可能的查询,而不必听状态的变化来判断INT当前基站的小区ID,因为相邻小区站CAL也可以从telephonyManager调查。

There are various APIs and it looks like i'd have to use different APIs telephonyManager and PhoneStateListener. I'm a littlebit confused, as I think this should be available in one interface. Also I think that it should be possible to poll the CellID of the current Base Station instead of having to listen to State Changes to determine int, since the Neighbouring Cell Stations cal also be polled from the telephonyManager.

你能告诉我怎样才能得到上述规定的数据?

Can you tell me how I can get the data specified above?

推荐答案

新斯库尔路:API 17更漂亮,更清洁,但还是太新

New skool-way: API 17 much nicer and cleaner, but still too new.

List<CellInfo> cellInfos = (List<CellInfo>) this.telephonyManager.getAllCellInfo();

for(CellInfo cellInfo : cellInfos)
{
    CellInfoGsm cellInfoGsm = (CellInfoGsm) cellInfo;

    CellIdentityGsm cellIdentity = cellInfoGsm.getCellIdentity();
    CellSignalStrengthGsm cellSignalStrengthGsm = cellInfoGsm.getCellSignalStrength();

    Log.d("cell", "registered: "+cellInfoGsm.isRegistered());
    Log.d("cell", cellIdentity.toString());         
    Log.d("cell", cellSignalStrengthGsm.toString());
}

旧的API不提供一个非常令人满意的解决方案。但这里的老斯库尔方式:

The old API doesn't provide a very satisfying solution. But here's the old-skool way:

this.telephonyManager = (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE);
this.phoneStateListener = setupPhoneStateListener();
this.telephonyManager.listen(phoneStateListener, PhoneStateListener.LISTEN_CELL_LOCATION);
this.telephonyManager.listen(phoneStateListener, PhoneStateListener.LISTEN_DATA_CONNECTION_STATE);
this.telephonyManager.listen(phoneStateListener, PhoneStateListener.LISTEN_SIGNAL_STRENGTHS);

// This part is used to listen for properties of the neighboring cells
List<NeighboringCellInfo> neighboringCellInfos = this.telephonyManager.getNeighboringCellInfo();
for(NeighboringCellInfo neighboringCellInfo : neighboringCellInfos)
{
    neighboringCellInfo.getCid();
    neighboringCellInfo.getLac();
    neighboringCellInfo.getPsc();
    neighboringCellInfo.getNetworkType();
    neighboringCellInfo.getRssi();

    Log.d("cellp",neighboringCellInfo.toString());
}

public PhoneStateListener setupPhoneStateListener()
{
    return new PhoneStateListener() {

        /** Callback invoked when device cell location changes. */
        @SuppressLint("NewApi")
        public void onCellLocationChanged(CellLocation location)
        {
            GsmCellLocation gsmCellLocation = (GsmCellLocation) location;
            gsmCellLocation.getCid();
            gsmCellLocation.getLac();
            gsmCellLocation.getPsc();

            Log.d("cellp", "registered: "+gsmCellLocation.toString());
        }

        /** invoked when data connection state changes (only way to get the network type) */
        public void onDataConnectionStateChanged(int state, int networkType)
        {
            Log.d("cellp", "registered: "+networkType);
        }

        /** Callback invoked when network signal strengths changes. */
        public void onSignalStrengthsChanged(SignalStrength signalStrength)
        {
            Log.d("cellp", "registered: "+signalStrength.getGsmSignalStrength());
        }

    };
}

  • 不要忘记设置所有必要的权限 这种解决方案的问题是,我没有得到任何相邻小区信息,eventhough我设置:

    • Don't forget to set all the necessary permissions The problem with this solution is, that I don't get any neighboring cell info, eventhough i setup:

      使用-权限的Andr​​oid:名称=android.permission.ACCESS_COARSE_UPDATES

      uses-permission android:name="android.permission.ACCESS_COARSE_UPDATES"

      (请注意,我用的是三星手机,这是一个已知的问题,三星手机不支持相邻小区的上市)

      (note that i'm using a Samsung phone and it's a known issue that Samsung phones don't support the listing of neighboring cells)

      这篇关于安卓:得到的CellID和RSS基站和Neigboring细胞的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆