Hello everyone, i'm in need of some help, I'm working on an app that stores the location coordinates to a database when no Internet connection is available or cell phone connection, Upon the device re-gaining either Internet connection or cell phone connection, it will start uploading the saved coordinates to a server.
The part I need help is that I need to figure out how to send each record saved in the database one after the other, so far what I have works if there's only about 15 records saved, but if there's more than that I get an error related to the HttpUtils2 service.
This is the code i have for that part, i know is not the best way to do it which is why I need some help
and this is the error i get from the logs
i'm guessing i have to wait some time before submitting the next job from this error, hopefully Erel can shed some light on this.
Thanks anyone and everyone who is willing to help.
Thanks,
Walter
The part I need help is that I need to figure out how to send each record saved in the database one after the other, so far what I have works if there's only about 15 records saved, but if there's more than that I get an error related to the HttpUtils2 service.
This is the code i have for that part, i know is not the best way to do it which is why I need some help
B4X:
cursor2 = db.ExecQuery("SELECT ID, latitude, longitude, accuracy, speed, time FROM locationinfo")
rows = db.ExecQuerySingleResult("SELECT count(*) FROM locationinfo")
Log("number of records in database :" & rows)
Log("wi_fi " & wifi.GetSettings("wifi_on"))
If rows > 0 AND connection = "connected" OR server.GetMyWifiIP <> wifi_ip Then 'if there's records and internet conection then upload saved data to server
For i = 0 To rows - 1
cursor2.Position = i
latitude2 = cursor2.GetString("latitude")
longitude2 = cursor2.GetString("longitude")
accuracy2 = cursor2.GetString("accuracy")
speed2 = cursor2.GetString("speed")
time2 = cursor2.GetString("time")
coordinates1.Download("http://dev.cyprustech.net/tracking/controller.php?action=coordinate_update&username=" & s_username & "&password=" & s_password & "&i_user_id=" & s_UserID & "&" & "s_lat=" & latitude2 & "&s_long=" & longitude2 & "&s_accuracy=" & accuracy2 & "&s_speed=" & speed2 & "&d_time=" & time2 & "&b_from_saved=1")
db.ExecNonQuery("DELETE FROM locationinfo WHERE ID=" & i) 'delete record when it has been uploaded to server
Log("DELETING FROM locationinfo WHERE ID=" & i)
Log(latitude2 & " " & longitude2 & " " & accuracy2 & " " & speed2 & " " & time2)
DoEvents
Next
index = 0
cursor2.Close
End If
and this is the error i get from the logs
httpjob_getstring2 (B4A line: 120)
tr.Initialize2(File.OpenInput(HttpUtils2Service.TempFolder, taskId), Encoding)
java.io.FileNotFoundException: /mnt/sdcard/Android/data/com.genesis.cyprus/files/32 (No such file or directory)
at org.apache.harmony.luni.platform.OSFileSystem.open(Native Method)
at dalvik.system.BlockGuard$WrappedFileSystem.open(BlockGuard.java:232)
at java.io.FileInputStream.<init>(FileInputStream.java:80)
at anywheresoftware.b4a.objects.streams.File.OpenInput(File.java:197)
at com.genesis.cyprus.httpjob._getstring2(httpjob.java:301)
at com.genesis.cyprus.httpjob._getstring(httpjob.java:276)
at com.genesis.cyprus.gps_tracker._handlecoordinates1(gps_tracker.java:327)
at com.genesis.cyprus.gps_tracker._jobdone(gps_tracker.java:392)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:507)
at anywheresoftware.b4a.BA.raiseEvent2(BA.java:169)
at anywheresoftware.b4a.keywords.Common$4.run(Common.java:930)
at android.os.Handler.handleCallback(Handler.java:587)
at android.os.Handler.dispatchMessage(Handler.java:92)
at android.os.Looper.loop(Looper.java:130)
at android.app.ActivityThread.main(ActivityThread.java:3806)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:507)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:839)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597)
at dalvik.system.NativeStart.main(Native Method)
java.lang.RuntimeException: java.lang.RuntimeException: java.io.FileNotFoundException: /mnt/sdcard/Android/data/com.genesis.cyprus/files/32 (No such file or directory)
at anywheresoftware.b4a.keywords.Common$4.run(Common.java:933)
at android.os.Handler.handleCallback(Handler.java:587)
at android.os.Handler.dispatchMessage(Handler.java:92)
at android.os.Looper.loop(Looper.java:130)
at android.app.ActivityThread.main(ActivityThread.java:3806)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:507)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:839)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597)
at dalvik.system.NativeStart.main(Native Method)
Caused by: java.lang.RuntimeException: java.io.FileNotFoundException: /mnt/sdcard/Android/data/com.genesis.cyprus/files/32 (No such file or directory)
at anywheresoftware.b4a.BA.raiseEvent2(BA.java:195)
at anywheresoftware.b4a.keywords.Common$4.run(Common.java:930)
... 9 more
Caused by: java.io.FileNotFoundException: /mnt/sdcard/Android/data/com.genesis.cyprus/files/32 (No such file or directory)
at org.apache.harmony.luni.platform.OSFileSystem.open(Native Method)
at dalvik.system.BlockGuard$WrappedFileSystem.open(BlockGuard.java:232)
at java.io.FileInputStream.<init>(FileInputStream.java:80)
at anywheresoftware.b4a.objects.streams.File.OpenInput(File.java:197)
at com.genesis.cyprus.httpjob._getstring2(httpjob.java:301)
at com.genesis.cyprus.httpjob._getstring(httpjob.java:276)
at com.genesis.cyprus.gps_tracker._handlecoordinates1(gps_tracker.java:327)
at com.genesis.cyprus.gps_tracker._jobdone(gps_tracker.java:392)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:507)
at anywheresoftware.b4a.BA.raiseEvent2(BA.java:169)
... 10 more
i'm guessing i have to wait some time before submitting the next job from this error, hopefully Erel can shed some light on this.
Thanks anyone and everyone who is willing to help.
Thanks,
Walter