I would like to get CellInfoGsm data, but I got some error.
CellInfoGsm is subclass of CellInfo. I don’t know how to get the CellInfoGsm data.
Could someone help me to write the right code?
TelephonyManager TM = (TelephonyManager) this.getSystemService(Context.TELEPHONY_SERVICE);
(CellInfoGsm) cellinfogsm = (CellInfoGsm)TM.getAllCellInfo();
You have a couple of errors in your code.
(CellInfoGsm) cellinfogsmneeds to be changed toCellInfoGsm cellinfogsmas you are not casting anything there.getAllCellInfo();returns a List. You must first choose one element in that list and work with it. Do this by writingCellInfoGsm cellinfogsm = (CellInfoGsm)TM.getAllCellInfo().get(0);I used 0 as an example, you will first need to check the list’s size then choose a CellInfo Object.