Android Question Java Lang Object - Access android.telephony.CellSignalStrength

Derek Johnson

Active Member
Licensed User
Longtime User
I'm trying to use the Android Documentation in conjunction with the Java Language object to get the value of some properties.


This is the code that I am trying

B4X:
Dim jo,jo2 As JavaObject
Dim ASU As String
Try
    jo2 = jo.InitializeStatic("android.telephony.CellSignalStrength")
    log("Got Signal Strength object OK")
    ASU=jo2.RunMethod("getAsuLevel", Null)
    Log("ASU= " & ASU)
Catch
    Log("Java Error: " & LastException.Message)
End Try

The first part worked Ok and the jo2 object was initialised.
However I get this error when I try to get the ASU info:

Java Error: java.lang.IllegalArgumentException: Expected receiver of type android.telephony.CellSignalStrength, but got java.lang.Class<android.telephony.CellSignalStrength>

Where am I going wrong with this? If I can sort this out I'll be well on my way to being able to make better use of the Android Documentation and Methods,
 

Roycefer

Well-Known Member
Licensed User
Longtime User
Have you tried the other Initialize methods? Maybe you shouldn't try to create it as static. Try InitializeInstance. Also, looking at the documentation, android.telephony.CellSignalStrength is an abstract base class. Maybe you should try instantiating one of its subclasses like CellSignalStrengthCdma.
 
Upvote 0

Derek Johnson

Active Member
Licensed User
Longtime User
Roycefer , Thanks for the info and links.

This code below now compiles OK and runs.

B4X:
Dim css,jo As JavaObject
Dim result As String

    css = jo.InitializeNewInstance("android.telephony.SignalStrength",Null)
    Log("Object Test result:"  & css)
  
    result= css.RunMethod("isGsm",Null)
    Log("Is GSM:"  & result)
  
    result= css.RunMethod("toString",Null)
    Log("ToString:"  & result)

    result= css.RunMethod("hashCode",Null)
    Log("hashCode:"  & result)

    result= css.RunMethod("getGsmSignalStrength",Null)
    Log("Signal Strength:"  & result)
      
    result= css.RunMethod("getGsmOemSignalStrength",Null)
    Log("OEM Signal Strength:"  & result)
  
    result= css.RunMethod("getGsmBitErrorRate",Null)
    Log("Bit error rate:"  & result)
  
    result= css.RunMethod("getAsuLevel",Null)
    Log("getAsuLevel:"  & result)

This only gives the initial values however, it does not read anything from the phone.


How do I make this code get a new set of values? DO I need to use Events to do this?

(I was hoping to be able to find some further information about the 2nd Sim Signal Info by using some of the methods in the android.telephony.SignalStrength object.)
 
Upvote 0
Cookies are required to use this site. You must accept them to continue using the site. Learn more…