Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/208.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android:获取基站和邻近小区的CellID和RSS_Android_Telephony_Telephonymanager_Cellid_Phone State Listener - Fatal编程技术网

Android:获取基站和邻近小区的CellID和RSS

Android:获取基站和邻近小区的CellID和RSS,android,telephony,telephonymanager,cellid,phone-state-listener,Android,Telephony,Telephonymanager,Cellid,Phone State Listener,我正在尝试获取以下数据: 基站:CellID和RSS(识别哪一个是基站) 所有邻近电台:CellID和RSS 有各种API,看起来我必须使用不同的API telephonyManager和PhoneStateListener。我有点困惑,因为我认为这应该在一个界面中可用。另外,我认为应该可以轮询当前基站的CellID,而不必听状态变化来确定int,因为相邻的Cell站cal也可以从telephonyManager进行轮询 你能告诉我如何获得上面指定的数据吗?新的skool方式:API 17更

我正在尝试获取以下数据:

  • 基站:CellID和RSS(识别哪一个是基站)
  • 所有邻近电台:CellID和RSS
有各种API,看起来我必须使用不同的API telephonyManager和PhoneStateListener。我有点困惑,因为我认为这应该在一个界面中可用。另外,我认为应该可以轮询当前基站的CellID,而不必听状态变化来确定int,因为相邻的Cell站cal也可以从telephonyManager进行轮询


你能告诉我如何获得上面指定的数据吗?

新的skool方式:API 17更漂亮、更干净,但还是太新了

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());
}
List cellInfos=(List)this.telephonyManager.getAllCellInfo();
用于(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不能提供非常令人满意的解决方案。但这里有一个古老的skool方法:

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());
        }

    };
}
this.telephonyManager=(telephonyManager)context.getSystemService(context.TELEPHONY_服务);
this.phoneStateListener=setupPhoneStateListener();
this.telephonyManager.listen(phoneStateListener,phoneStateListener.listen\u CELL\u LOCATION);
this.telephonyManager.listen(phoneStateListener,phoneStateListener.listen\u数据\u连接\u状态);
this.telephonyManager.listen(phoneStateListener,phoneStateListener.listen\u信号强度);
//此部分用于侦听相邻单元的属性
List neightringcellinfos=this.telephonyManager.getneightringcellinfo();
用于(NeightringCellInfo NeightringCellInfo:NeightringCellInfos)
{
neightringcellinfo.getCid();
neightringcellinfo.getLac();
neightringcellinfo.getPsc();
NeightringCellInfo.getNetworkType();
neightringcellinfo.getRssi();
Log.d(“cellp”,neighbringcellinfo.toString());
}
公共PhoneStateListener设置PhoneStateListener()
{
返回新的PhoneStateListener(){
/**当设备单元位置更改时调用回调*/
@SuppressLint(“新API”)
CellLocation更改后的公共void(CellLocation位置)
{
GsmCellLocation GsmCellLocation=(GsmCellLocation)位置;
gsmCellLocation.getCid();
gsmCellLocation.getLac();
gsmCellLocation.getPsc();
Log.d(“cellp”,“registered:+gsmCellLocation.toString());
}
/**数据连接状态更改时调用(获取网络类型的唯一方法)*/
公共无效onDataConnectionStateChanged(int状态,int网络类型)
{
Log.d(“cellp”,“registered:+networkType”);
}
/**当网络信号强度改变时调用回调*/
信号强度上的公共无效已更改(信号强度信号强度)
{
Log.d(“cellp”,“registered:”+signalStrength.getGsmSignalStrength());
}
};
}
  • 不要忘记设置所有必要的权限 此解决方案的问题是,即使我设置了以下内容,也无法获取任何相邻单元格的信息:

    使用权限android:name=“android.permission.ACCESS\u\u更新”


(请注意,我使用的是三星手机,众所周知,三星手机不支持相邻手机的列表)

我得到一个
android.telephony.CellInfoWcdma无法转换为android.telephony.CellInfoGsm
on
CellInfoGsm CellInfoGsm=(CellInfoGsm)cellInfo代码可能不是100%工作,API太新,在我编写代码时无法在我的手机上运行。如果您有解决方案,请发布新问题和/或建议编辑。获取此数据合法吗?