0
実際に私は、セルID LAC RSSIなどのセルパラメータを取得する方法を探していますが、私が使用したコードを熟読して見ることができますが、それはうまくいきません。アンドロイドで細胞IDとLACを取得する方法は?
public final class MainActivity extends AppCompatActivity {
PhoneStateListener phoneStateListener;
TelephonyManager telephonyManager = (TelephonyManager)getSystemService(TELEPHONY_SERVICE);
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
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());
}
};
}
}