Hello,
I am working on a car alarm application running on a old Android phone (Galaxy S4 mini - Android 4.4.2) and I am at the very early stages. I have progressively added support for intercepting sms and calls, monitoring battery level and accelerometer. Now I want to add support for monitoring GPS and I face a strange issue. I receive an error in the log file, although the program does not crash and seems to work correctly. Here's the error:
What is confusing me is that even if I hit Clear button in the Logs window and I restart on the phone the B4A-Bridge, when I run the application, it seem to display some older logged data. As you can see above, before the error is reported there are some Lat, Lon, Speed info logged from the previous run of the program. Also, one note is that the error is reported before *** Service (starter) Create *** event, so I suspect it has something to do with the B4A-Bridge application and not with my program.
I have tried to stop and start the B4A-Bridge on the phone, put this seems to be a process running in background and I could not kill it.
Here is how my manifest looks like:
Starter module code:
I am using latest version of B4A, namely 7.01 and B4A-Bridge v2.31
Thank you for any hint you have on what is the cause of the error.
I am working on a car alarm application running on a old Android phone (Galaxy S4 mini - Android 4.4.2) and I am at the very early stages. I have progressively added support for intercepting sms and calls, monitoring battery level and accelerometer. Now I want to add support for monitoring GPS and I face a strange issue. I receive an error in the log file, although the program does not crash and seems to work correctly. Here's the error:
B4X:
Lat = 44:23.65651
Lon = 26:5.74051
Speed =0
java.lang.RuntimeException: java.net.SocketException: Socket closed
at anywheresoftware.b4a.ShellBA.raiseEvent2(ShellBA.java:170)
at anywheresoftware.b4a.BA.raiseEvent(BA.java:166)
at anywheresoftware.b4a.phone.Phone$PhoneSensors$1.onSensorChanged(Phone.java:1098)
at android.hardware.SystemSensorManager$SensorEventQueue.dispatchSensorEvent(SystemSensorManager.java:474)
at android.os.MessageQueue.nativePollOnce(Native Method)
at android.os.MessageQueue.next(MessageQueue.java:138)
at android.os.Looper.loop(Looper.java:131)
at android.app.ActivityThread.main(ActivityThread.java:5593)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:515)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1283)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1099)
at dalvik.system.NativeStart.main(Native Method)
Caused by: java.net.SocketException: Socket closed
at libcore.io.Posix.sendtoBytes(Native Method)
at libcore.io.Posix.sendto(Posix.java:156)
at libcore.io.BlockGuardOs.sendto(BlockGuardOs.java:177)
at libcore.io.IoBridge.sendto(IoBridge.java:466)
at java.net.PlainSocketImpl.write(PlainSocketImpl.java:508)
at java.net.PlainSocketImpl.access$100(PlainSocketImpl.java:46)
at java.net.PlainSocketImpl$PlainSocketOutputStream.write(PlainSocketImpl.java:270)
at java.io.BufferedOutputStream.flushInternal(BufferedOutputStream.java:185)
at java.io.BufferedOutputStream.flush(BufferedOutputStream.java:85)
at anywheresoftware.b4a.shell.ShellConnector.sendControlMessage(ShellConnector.java:62)
at anywheresoftware.b4a.shell.Shell.raiseEventImpl(Shell.java:297)
at anywheresoftware.b4a.shell.Shell.raiseEvent(Shell.java:249)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:515)
at anywheresoftware.b4a.ShellBA.raiseEvent2(ShellBA.java:139)
... 12 more
*** Service (starter) Create ***
** Service (starter) Start **
** Activity (main) Create, isFirst = true **
** Activity (main) Resume **
BatteryChanged. Level: 94, Plugged: false
** Service (starter) Start **
Lat = 44:23.65913
Lon = 26:5.74388
Speed =0
What is confusing me is that even if I hit Clear button in the Logs window and I restart on the phone the B4A-Bridge, when I run the application, it seem to display some older logged data. As you can see above, before the error is reported there are some Lat, Lon, Speed info logged from the previous run of the program. Also, one note is that the error is reported before *** Service (starter) Create *** event, so I suspect it has something to do with the B4A-Bridge application and not with my program.
I have tried to stop and start the B4A-Bridge on the phone, put this seems to be a process running in background and I could not kill it.
Here is how my manifest looks like:
B4X:
AddManifestText(
<uses-sdk android:minSdkVersion="5" android:targetSdkVersion="19"/>
<supports-screens android:largeScreens="true"
android:normalScreens="true"
android:smallScreens="true"
android:anyDensity="true"/>)
SetApplicationAttribute(android:icon, "@drawable/icon")
SetApplicationAttribute(android:label, "$LABEL$")
'End of default text.
'CarAlarm specific permissions
AddManifestText(<uses-feature android:name="android.hardware.location.gps"/>)
AddPermission(android.permission.SEND_SMS)
AddPermission(android.permission.RECEIVE_SMS)
AddReceiverText(Starter,
<intent-filter android:priority="2147483647">
<action android:name="android.provider.Telephony.SMS_RECEIVED" />
</intent-filter>)
Starter module code:
B4X:
#Region Service Attributes
#StartAtBoot: True
#ExcludeFromLibrary: True
#End Region
Sub Process_Globals
'These global variables will be declared once when the application starts.
'These variables can be accessed from all modules.
Dim notif As Notification
Dim phoneId As PhoneId
Dim phoneEvents As PhoneEvents
Dim smsInterceptor As SmsInterceptor
Dim accelerometer As PhoneSensors
Dim gps As GPS
End Sub
Sub Service_Create
'This is the program entry point.
'This is a good place to load resources that are not specific to a single activity.
Starter_PhoneEvents_Init
Starter_SmsInterceptor_Init
Starter_Accelerometer_Init
Starter_Gps_Init
' Start running the service in foreground, in order not to be killed by Android OS
Starter_RunForeground
End Sub
Sub Service_Start (StartingIntent As Intent)
End Sub
Sub Service_TaskRemoved
'This event will be raised when the user removes the app from the recent apps list.
End Sub
'Return true to allow the OS default exceptions handler to handle the uncaught exception.
Sub Application_Error (Error As Exception, StackTrace As String) As Boolean
Return True
End Sub
Sub Service_Destroy
End Sub
'--------------------------------------------------------------------------
Sub Starter_PhoneEvents_Init
' Initialize PhoneEvents in order to be able to capure events
phoneEvents.InitializeWithPhoneState("PhoneEvents", phoneId)
End Sub
Sub Starter_SmsInterceptor_Init
smsInterceptor.Initialize("SmsInterceptor")
End Sub
Sub Starter_Accelerometer_Init
accelerometer.Initialize(accelerometer.TYPE_Accelerometer)
If accelerometer.StartListening("Accelerometer") = False Then
LogColor("Accelerometer sensor is not supported!", Colors.Red)
End If
End Sub
Sub Starter_Gps_Init
gps.Initialize ("GPS")
gps.Start(0, 0)
End Sub
Sub Starter_RunForeground
notif.Initialize
notif.Icon = "icon"
notif.SetInfo("Car Alarm", "Tap to access application", Main)
notif.Sound=False
notif.Vibrate=False
notif.Light=False
notif.OnGoingEvent=True
Service.StartForeground(1, notif)
End Sub
'----------------------------------------------------------------------------
' Events
'----------------------------------------------------------------------------
Sub PhoneEvents_BatteryChanged(Level As Int, Scale As Int, Plugged As Boolean, Intent As Intent)
' Pass information to BatteryMonitor module
modBatteryMonitor.Process(Level, Plugged)
End Sub
Sub PhoneEvents_PhoneStateChanged (State As String, IncomingNumber As String, Intent As Intent)
' Pass information to PhoneCallMonitor module
modPhoneCallMonitor.Process(State, IncomingNumber, Intent)
End Sub
Sub SmsInterceptor_MessageReceived (From As String, Body As String) As Boolean
' Pass information to SmsMonitor module
modSmsMonitor.Process(From, Body)
Return True
End Sub
Sub Accelerometer_SensorChanged (Values() As Float)
' Pass information to AccelerometerMonitor module
modAccelerometerMonitor.Process(Values)
End Sub
Sub GPS_LocationChanged (location As Location)
' Pass information to GpsMonitor module
modGpsMonitor.Process(location)
End Sub
I am using latest version of B4A, namely 7.01 and B4A-Bridge v2.31
Thank you for any hint you have on what is the cause of the error.
Last edited: