Android Question PhoneStateListener - Getting signal strength

trueboss323

Active Member
Licensed User
Longtime User
Hello all, I need help with trying to receive the phone signal's strength with this library. I want to read the signal strength just once, instead of automatic. So I try using this code:

B4X:
Dim PSL As PhoneStateListener
...
Sub button1_click
    Msgbox(PSL.CellLocation,"")
    Msgbox(PSL.GsmSignalStrength,"")
End Sub

The first Msgbox results in
[3812,242559177,-1]

but the second gives me an error
An error has occured in
sub:mainbutton1_click
(java line:234)
java.lang.
NullPointerException
Continue?
 

trueboss323

Active Member
Licensed User
Longtime User
1. Use Log instead of Msgbox.
2. Can you post the full error message from the logs?

Have you tried to handle the onSignalStrengthsChanged event?

Here is the full log I get:
** Activity (main) Create, isFirst = true **
PhoneStateListener has been initialized.
** Activity (main) Resume **
[3032,7992,-1]
Error occurred on line: 50 (Main)
java.lang.NullPointerException: Attempt to invoke virtual method 'int android.telephony.SignalStrength.getGsmSignalStrength()' on a null object reference
at com.rootsoft.phonestatelistener.PSL.getGsmSignalStrength(PSL.java:290)
at java.lang.reflect.Method.invoke(Native Method)
at java.lang.reflect.Method.invoke(Method.java:372)
at anywheresoftware.b4a.shell.Shell.runMethod(Shell.java:703)
at anywheresoftware.b4a.shell.Shell.raiseEventImpl(Shell.java:337)
at anywheresoftware.b4a.shell.Shell.raiseEvent(Shell.java:247)
at java.lang.reflect.Method.invoke(Native Method)
at java.lang.reflect.Method.invoke(Method.java:372)
at anywheresoftware.b4a.ShellBA.raiseEvent2(ShellBA.java:134)
at anywheresoftware.b4a.BA.raiseEvent2(BA.java:157)
at anywheresoftware.b4a.BA.raiseEvent(BA.java:153)
at anywheresoftware.b4a.objects.ViewWrapper$1.onClick(ViewWrapper.java:78)
at android.view.View.performClick(View.java:4856)
at android.view.View$PerformClick.run(View.java:19956)
at android.os.Handler.handleCallback(Handler.java:739)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:211)
at android.app.ActivityThread.main(ActivityThread.java:5371)
at java.lang.reflect.Method.invoke(Native Method)
at java.lang.reflect.Method.invoke(Method.java:372)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:945)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:740)

I tried to use the onSignalChange event but it wouldn't get triggered. Plus i dont think that would be relevant for me since I only want to get the signal once and I assume that event is used for automatic.
 
Upvote 0

KY Leng

Member
Licensed User
Longtime User
but the event seem not fire ...
B4X:
Sub PSL_onSignalStrengthsChanged (signalStrength As String)
    'ToastMessageShow(signalStrength, False)
    'ToastMessageShow(PSL.CdmaDbm, False)
    Log("SignalStrength : " & signalStrength)
End Sub
 
Upvote 0

Martin Larsen

Active Member
Licensed User
Longtime User
Excuse me for opening this old thread, but I have the exact same problem as in #7 so I feel it is appropriate to use the same thread.

onSignalStrengthsChanged is apparently never fired. To trigger signal strength change I put the phone into my microwave oven (not turned on!) but the event is never fired.

I use the sample program included with the library.
 
Upvote 0

Martin Larsen

Active Member
Licensed User
Longtime User
Ok. I just thought that it would be nice for users coming to this thread via the search function to get an update on the problem since it was never solved for the OP.

I will start a new thread.
 
Upvote 0
Top