6

Próbuję uzyskać następujące dane: stacjaAndroid: uzyskać CellID i RSS dla stacji bazowych i Neigboring Cells

  • Base: CellID i RSS (rozpoznanie, który z nich jest stacja bazowa)
  • Dla Wszystkie sąsiedniej Światłej stacje: CellID i RSS

Istnieją różne interfejsy API i wygląda jakbym musiał użyć różnych API telephonyManager i PhoneStateListener. Jestem trochę zdezorientowany, ponieważ myślę, że powinien on być dostępny w jednym interfejsie. Myślę też, że powinno być możliwe odpytywanie CellID obecnej stacji bazowej zamiast słuchania zmian stanu w celu określenia int, ponieważ sąsiednie stacje komórkowe będą również odpytywane z menadżera telefonii.

Czy możesz mi powiedzieć, jak mogę uzyskać dane określone powyżej?

Odpowiedz

6

Nowa metoda skool: API 17 jest o wiele ładniejsza i czystsza, ale wciąż za nowa.

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

Stare API nie zapewnia bardzo satysfakcjonującego rozwiązania. Ale oto sposób stary-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()); 
     } 

    }; 
} 
  • Nie zapomnij ustawić wszystkie niezbędne uprawnienia Problem z tego rozwiązania jest to, że nie dostanę żadnej informacji komórki sąsiadującej, mimo iż ja setup :

    wykorzystuje-pozwolenie android: name = "android.permission.ACCESS_COARSE_UPDATES"

(zauważ, że używam telefonu Samsung i jest to znany problem, że telefony Samsung don 't obsługa listy sąsiednich komórek)

+1

Dostaję 'android.telephony.CellInfoWcdma nie można przesłać do android.telephony.CellInfoGsm' na' CellInfoGsm cellInfoGsm = (CellInfoGsm) cellInfo; ' – msysmilu

+0

Kod może nie być 100% działa, API był zbyt nowy, aby uruchomić na moim telefonie w momencie, gdy napisałem kod. Opublikuj nowe pytanie i/lub zaproponuj zmianę, jeśli masz rozwiązanie. – ndrizza

+0

Czy pobranie tych danych jest legalne? – heximal

Powiązane problemy