Android Question Object Cast help

Ohanian

Active Member
Licensed User
Longtime User
Hello,

i'm using this code to get cell info :

B4X:
Dim Cell As String
    Dim telMgr As JavaObject = GetContext.RunMethod("getSystemService", Array("phone"))   
    Dim LstCellInfo As List = telMgr.RunMethod("getAllCellInfo", Null)
    If (LstCellInfo.Size > 0) Then
        Cell = LstCellInfo.Get(0)
       
        Log(Cell)
    End If

the result is something like this :
B4X:
CellInfoWcdma:{mRegistered=YES mTimeStampType=oem_ril mTimeStamp=129299157826521ns CellIdentityWcdma:{ mMcc=432 mMnc=11 mLac=34200 mCid=2693318 mPsc=361 mUarfcn=0} CellSignalStrengthWcdma: ss=18 ber=62}

is there any method to convert this string (Cell) to an object so i can access to the parameters (mMcc, mMnc & ...)?
 

stevel05

Expert
Licensed User
Longtime User
The returned value from LstCellInfo.Get(0) is a CellInfo Object, It is displaying the result of the toString method from CellInfo.

If you Dim Cell As JavaObject instead of String, you will then be able to access it's methods. I don't know if there is an existing library that includes CellInfo.
 
Upvote 0

Ohanian

Active Member
Licensed User
Longtime User
The returned value from LstCellInfo.Get(0) is a CellInfo Object, It is displaying the result of the toString method from CellInfo.

If you Dim Cell As JavaObject instead of String, you will then be able to access it's methods. I don't know if there is an existing library that includes CellInfo.

Hi,

here's the modified code, but the result of the methods is 0 :

B4X:
        Dim Cell As JavaObject
        Cell = LstCellInfo.Get(0)
        Cell = Cell.RunMethod("getCellIdentity",Null)
        Log(Cell.RunMethod("getMcc",Null)) ' > 0
        Log(Cell.RunMethod("getCid",Null)) ' > 0
 
Upvote 0

DonManfred

Expert
Licensed User
Longtime User
Upvote 0
Top