B4A Library JavaObject library

Status
Not open for further replies.

Erel

B4X founder
Staff member
Licensed User
Longtime User
Thank you very much indeed! At least this is something positive after a weekend with heaps of problems with newer versions of the Android SDK. In the end I had to restore Windows to at least get B4A working again.
As I wrote to you in another thread, you are using an old version of B4A. Upgrade to the latest version and it will work with the latest version of Android SDK.

As it reads now, everyone would think that it is the old version 1.20.
I will update it. JavaObject is part of the preinstalled libraries for quite a long time so most developers already use the latest version.
 

KY Leng

Member
Licensed User
Longtime User
Good morning,

I install "Network Cell Info Lite" and it work fine. However, when I want to do it with B4A using JavaObject, the result is not correct.
Below is my code:

B4X:
Sub Activity_Create(FirstTime As Boolean)
    'Do not forget to load the layout file created with the visual designer. For example:
    'Activity.LoadLayout("Layout1")
   
    Dim css, jo As JavaObject
    Dim result As String

    css = jo.InitializeNewInstance("android.telephony.CellSignalStrengthLte",Null)
    Log("Object Test result: "  & css)
    result= css.RunMethod("hashCode",Null)
    Log("hashCode: "  & result)
    result= css.RunMethod("getDbm",Null)
    Log("Signal Strength as dBm: "  & result)
    result= css.RunMethod("getLevel",Null)
    Log("Signal level as an int from [0..4]: "  & result) 
    result= css.RunMethod("getAsuLevel",Null)
    Log("Signal level as an asu value between [0..31]: "  & result)   
   
    css = jo.InitializeNewInstance("android.telephony.CellIdentityLte",Null)
    Log("Object Test result: "  & css)   
    result= css.RunMethod("hashCode",Null)
    Log("hashCode: "  & result)
    result= css.RunMethod("getMcc",Null)
    Log("MCC: "  & result)
    result= css.RunMethod("getMnc",Null)
    Log("MNC: "  & result)
    result= css.RunMethod("getPci",Null)
    Log("PCI: "  & result)
    result= css.RunMethod("getTac",Null)
    Log("TAC: "  & result)   
    result= css.RunMethod("getCi",Null)
    Log("CI: "  & result)
   
End Sub

And the result after compile look like this:

Object Test result: (CellSignalStrengthLte) CellSignalStrengthLte: ss=2147483647 rsrp=2147483647 rsrq=2147483647 rssnr=2147483647 cqi=2147483647 ta=2147483647
hashCode: -186
Signal Strength as dBm: 2147483647
Signal level as an int from [0..4]: 0
Signal level as an asu value between [0..31]: 97
Object Test result: (CellIdentityLte) CellIdentityLte:{ mMcc=2147483647 mMnc=2147483647 mCi=2147483647 mPci=2147483647 mTac=2147483647}
hashCode: -2119808802
MCC: 2147483647
MNC: 2147483647
PCI: 2147483647
TAC: 2147483647
CI: 2147483647


Do I miss something ?
Best regards,
 
Last edited:

KY Leng

Member
Licensed User
Longtime User
1. Please use [code]code here...[/code] tags when posting code.
2. Please start a new thread for this question.

If you can tell us where we can find the Java Code and How the Java Code can be call in B4A, I think we don't need to bother you again... Please forgive me, I cannot find the tutorial related to this or in-line Java code that is easy to understand... If we know Java well, no need to use B4A, right ?
 

JordiCP

Expert
Licensed User
Longtime User
Do I miss something ?
Best regards,

Your Java code looks correct, and the results make sense. Everything is described in the android documentation

According to https://developer.android.com/reference/android/telephony/CellIdentityLte.html ,
B4X:
int getMnc()
Returns:
2 or 3-digit Mobile Network Code, 0..999, Integer.MAX_VALUE if unknown
(and the value 2147483647 that you are obtaining is INTEGER.MAX_VALUE, so it is unknown)


Also, this log
"Signal level as an asu value between [0..31]: 97"
is incorrect, since documentation in , https://developer.android.com/reference/android/telephony/CellSignalStrengthLte.html#getAsuLevel() says
B4X:
int getAsuLevel ()
Get the LTE signal level as an asu value between 0..97, 99 is unknown Asu is calculated based on 3GPP RSRP. Refer to 3GPP 27.007 (Ver 10.3.0) Sec 8.69
, so 97 is also a valid value.


Then, if the app reports different values on the same device (and under the same conditions), perhaps you are addressing the wrong classes or the app is using a non-official API. Are you connected to LTE?
You could try with android.telephony.CellIdentityGSM, android.telephony.CellIdentityWCDMA, .... and android.telephony.CellSignalStrengthWCDMA, ...... perhaps the app is choosing which is the appropiate one according to the visible networks type
 

KY Leng

Member
Licensed User
Longtime User

Thank you very much JordiCP for the response.
However, I already verify my mobile service, it is 4G.
Moreover, if I use below code, it give me the result, just don't have Earfcn that I want.
B4X:
Sub Get_Cell_Info
    '----------------------------------------------------------------------------------
   
    Dim telMgr As JavaObject = GetContext.RunMethod("getSystemService", Array("phone"))
    Dim Cell As String
    Dim Pos1, Pos2 As Int 
   
    Try       
        Dim OperatorName As String = telMgr.RunMethod("getNetworkOperatorName", Null)   
        Log("> NetworkOperatorName: " & OperatorName)
        
        Dim DataNetworkType As Int = telMgr.RunMethod("getDataNetworkType", Null)   
        Log("> DataNetworkType: " & DataNetworkType)
        
        Dim CellLocation As String = telMgr.RunMethod("getCellLocation", Null)   
        Log("> CellLocation: " & CellLocation)
       
        Dim LstCellInfo As List = telMgr.RunMethod("getAllCellInfo", Null)   
        If (LstCellInfo.Size > 0) Then    
            Cell = LstCellInfo.Get(0)
            Log("> Main Cell.Infor=" & Cell)
        End If
    Catch
        Log(LastException.Message)
        ToastMessageShow(LastException.Message, True)
    End Try
    '----------------------------------------------------
End Sub

Sub GetContext As JavaObject
  Return GetBA.GetField("context")
End Sub

Sub GetBA As JavaObject
  Dim jo As JavaObject
  Dim cls As String = Me
  cls = cls.SubString("class ".Length)
  jo.InitializeStatic(cls)
  Return jo.GetFieldJO("processBA")
End Sub

And the result look like below for LTE:

> Main Cell.Infor=CellInfoLte:{mRegistered=YES mTimeStampType=oem_ril mTimeStamp=2605340075290ns CellIdentityLte:{ mMcc=520 mMnc=18 mCi=64812801 mPci=471 mTac=3101 mEarfcn=0} CellSignalStrengthLte: ss=24 rsrp=-99 rsrq=-4 rssnr=21 cqi=15 ta=2}

and my Android is version 7 already that is why I can see the field mEarfcn but it is always 0.

Looking forward to hearing from the group soon...
 
Status
Not open for further replies.
Cookies are required to use this site. You must accept them to continue using the site. Learn more…