質問

現在接続されているセルのCIDとLACを取得しようとしましたが、使用して

public void GetCid(){
  int CID;
  int LAC;
  GsmCellLocation xXx = new GsmCellLocation();
  CID = xXx.getCid();
  LAC = xXx.getLac();
  Toast output = Toast.makeText(getApplicationContext(), "Base station LAC is "+LAC+"\n" 
  +"Base station CID is " +CID, Toast.LENGTH_SHORT);
  output.show();
}

私が得る唯一のものは、両方のパラメーターの-1値です(私は2Gです)。私が何か間違っているのか、それとも現在のセルのcidとlacを取得する別の方法があるかもしれませんか?

役に立ちましたか?

解決

TelephonyManager telephonyManager = (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE);
CellLocation location = telephonyManager.getCellLocation();
GsmCellLocation gsmLocation = (GsmCellLocation) location;
int cellId = gsmLocation.getCid();
int lac = gsmLocation.getLac();
ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top