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

Discussion in 'Android Questions' started by Derek Johnson, Jul 16, 2015.

  1. Derek Johnson

    Derek Johnson Active Member Licensed 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

    Code:
    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:

    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,
     
  2. Roycefer

    Roycefer Well-Known Member Licensed 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.
     
    Derek Johnson likes this.
  3. Roycefer

    Roycefer Well-Known Member Licensed User

  4. Derek Johnson

    Derek Johnson Active Member Licensed User

    Roycefer , Thanks for the info and links.

    This code below now compiles OK and runs.

    Code:
    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.)
     
  5. Roycefer

    Roycefer Well-Known Member Licensed User

Loading...