Hello everyone. I face a problem and I can not find any solution.
I have create a test application using Default Project in B4A IDE that when I press or long press a button I make a http job.
The code in the Main Activity is the follow:
The layout contains only 1 button. There are no extra classess and the service starter is the same as the default one.
Manifest is the follow:
When I first compile the code it runs correctly. My server on ip: 10.0.0.205 and port: 8440 runs and accept the message so I receive in my app a success message. The problem occurs after device restart. If I power off the device (or restart it) and when it turns on, I get into my application and press the button. I receive instantly an error message while the postman receives success message, either I hit the button before that or after the button has been pressed. I noticed that if I leave my app idle for some minutes then if I press the button it will sent with success the post/get request.After that I have tried that if I make force close the app or turn on again the bridge ("START") or close and open the app or turn off WiFi and turn it on, it will send the request with success.
I realy do not understand why I face that error. If anyone knows anything, his/her help will be very helpful.
Note that I have test the code in B4A IDE Version 13.0, the library httputils is up to date (version 3.04), I have tried to install the app through bridge, or usb debugging or just installed the apk, I have test 3 different android devices and all of them has the same problem, I have compiled from 2 differents pc. While I faced problem using my app (the above code) I were testing my server using postman and the postman was working with no problem.
With regards,
Nikos.
I have create a test application using Default Project in B4A IDE that when I press or long press a button I make a http job.
The code in the Main Activity is the follow:
Main Activity:
#Region Project Attributes
#ApplicationLabel: TESTelev
#VersionCode: 1
#VersionName:
'SupportedOrientations possible values: unspecified, landscape or portrait.
#SupportedOrientations: unspecified
#CanInstallToExternalStorage: False
#BridgeLogger: True
#End Region
#Region Activity Attributes
#FullScreen: False
#IncludeTitle: True
#End Region
Sub Process_Globals
End Sub
Sub Globals
End Sub
Sub Activity_Create(FirstTime As Boolean)
Activity.LoadLayout("Layout")
End Sub
Sub Activity_Resume
End Sub
Sub Activity_Pause (UserClosed As Boolean)
End Sub
Sub Button1_Click
Dim j As HttpJob
Dim p As Phone
Dim user_agent As String
user_agent = Application.LabelName & "/" & Application.VersionCode & " (Android; API-LEVEL 30; " & p.Model & ")"
j.Initialize("j",Me)
j.Download("http://10.0.0.205:8440")
j.GetRequest.SetHeader("Connection", "Close")
j.GetRequest.SetHeader("User-Agent",user_agent)
j.GetRequest.SetHeader("Accept","*/*")
j.GetRequest.SetHeader("Accept-Encoding","gzip, deflate, br")
j.GetRequest.Timeout = 20000
Wait For (j) JobDone (j As HttpJob)
If j.Success Then
LogColor(j.GetString, Colors.Green)
ToastMessageShow("Success!",False)
Activity.Color=Colors.Green
Else
LogColor("** Get Request has been failed! **", Colors.Red)
ToastMessageShow("Fail!",False)
Activity.Color=Colors.Red
End If
j.Release
Sleep(500)
Activity.Color = Colors.White
End Sub
Sub Button1_LongClick
Dim link As String, Data As String
Dim user_agent As String
Dim p As Phone
user_agent = Application.LabelName & "/" & Application.VersionCode & " (Android; API-LEVEL 30; " & p.Model & ")"
link = "http://10.0.0.205:8440"
Data = "FL2"
Dim j As HttpJob, resp = "" As String
j.Initialize("j",Me)
j.PostString(link,Data)
j.GetRequest.SetContentType("text/plain")
j.GetRequest.SetHeader("AUTHORIZATION", "mypassword")
j.GetRequest.SetHeader("Connection", "Close")
j.GetRequest.SetHeader("Accept","*/*")
j.GetRequest.SetHeader("User-Agent",user_agent)
j.GetRequest.SetHeader("Accept-Encoding","gzip, deflate, br")
j.GetRequest.SetHeader("Cache-Control", "no-cache")
j.GetRequest.Timeout = 20000
Wait For (j) JobDone (j As HttpJob)
If j.Success Then
resp = j.GetString
LogColor(resp, Colors.Green)
ToastMessageShow("Success!",False)
Activity.Color=Colors.Green
Else
resp = j.ErrorMessage
LogColor("** Post Request has been failed! **", Colors.Red)
ToastMessageShow("Fail!",False)
Activity.Color=Colors.Red
End If
j.Release
Sleep(500)
Activity.Color = Colors.White
End Sub
The layout contains only 1 button. There are no extra classess and the service starter is the same as the default one.
Manifest is the follow:
Manifest:
AddManifestText(
<uses-sdk android:minSdkVersion="21" android:targetSdkVersion="33"/>
<supports-screens android:largeScreens="true"
android:normalScreens="true"
android:smallScreens="true"
android:anyDensity="true"/>)
SetApplicationAttribute(android:icon, "@drawable/icon")
SetApplicationAttribute(android:label, "$LABEL$")
CreateResourceFromFile(Macro, Themes.LightTheme)
CreateResourceFromFile(Macro, Core.NetworkClearText)
AddPermission("android.permission.INTERNET")
AddPermission("android.permission.ACCESS_WIFI_STATE")
AddPermission("android.permission.ACCESS_NETWORK_STATE")
AddPermission("android.permission.WRITE_EXTERNAL_STORAGE")
SetApplicationAttribute(android:usesCleartextTraffic, "true")
'End of default text.
When I first compile the code it runs correctly. My server on ip: 10.0.0.205 and port: 8440 runs and accept the message so I receive in my app a success message. The problem occurs after device restart. If I power off the device (or restart it) and when it turns on, I get into my application and press the button. I receive instantly an error message while the postman receives success message, either I hit the button before that or after the button has been pressed. I noticed that if I leave my app idle for some minutes then if I press the button it will sent with success the post/get request.After that I have tried that if I make force close the app or turn on again the bridge ("START") or close and open the app or turn off WiFi and turn it on, it will send the request with success.
I realy do not understand why I face that error. If anyone knows anything, his/her help will be very helpful.
Note that I have test the code in B4A IDE Version 13.0, the library httputils is up to date (version 3.04), I have tried to install the app through bridge, or usb debugging or just installed the apk, I have test 3 different android devices and all of them has the same problem, I have compiled from 2 differents pc. While I faced problem using my app (the above code) I were testing my server using postman and the postman was working with no problem.
With regards,
Nikos.