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.

CellSignalStrength
extends Object
java.lang.Object

↳android.telephony.CellSignalStrength
Abstract base class for cell phone signal strength related information.

...
Public Methods
abstract booleanequals(Object o)
Compares this instance with the specified object and indicates if they are equal.
abstract intgetAsuLevel()
Get the signal level as an asu value between 0..31, 99 is unknown

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.

Object Test result (SignalStrength) SignalStrength: 99 -1 -1 -1 -1 -1 -1 99 2147483647 2147483647 2147483647 2147483647 2147483647 gsm|lte 0 -108 -1 false 0 0 0 0 0 99 99 99 4 -1
Is GSM:true
ToString:SignalStrength: 99 -1 -1 -1 -1 -1 -1 99 2147483647 2147483647 2147483647 2147483647 2147483647 gsm|lte 0 -108 -1 false 0 0 0 0 0 99 99 99 4 -1
hashCode:-2147477658
Signal Strength:99
OEM Signal Strength:-108
Bit error rate:-1
getAsuLevel:99
** Activity (main) Pause, UserClosed = false **

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
Top