6

次のデータを取得しようとしています。

  • 基地局:CellIDとRSS(どちらが基地局であるかを認識する)
  • すべての近隣ステーションの場合:CellIDとRSS

さまざまなAPIがあり、telephonyManagerとPhoneStateListenerで異なるAPIを使用する必要があるようです。これは1つのインターフェイスで利用できるはずなので、少し混乱しています。また、隣接するセルステーションもtelephonyManagerからポーリングされるため、状態の変化をリッスンしてintを決定する代わりに、現在のベースステーションのCellIDをポーリングできるはずだと思います。

上記のデータを取得する方法を教えてください。

4

1 に答える 1

6

新しいskool-way: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());
}

古いAPIは、非常に満足のいくソリューションを提供していません。しかし、これが昔ながらの方法です。

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

    };
}
  • 必要なすべての権限を設定することを忘れないでください。このソリューションの問題は、次のように設定しても、隣接するセル情報を取得できないことです。

    使用-許可android:name = "android.permission.ACCESS_COARSE_UPDATES"

(私はSamsung電話を使用しており、Samsung電話が隣接セルのリストをサポートしていないことは既知の問題であることに注意してください)

于 2013-03-23T04:09:49.500 に答える