Android Question Http request under sleep state

Medexpert

Member
Licensed User
Longtime User
Dear All!


I try to collect GPS location and send it every 10 minutes.
I used the StartServiceAt function to start the service under Android 7.0
The service successful get the GPS data, but it has some problem with the sending the data.
One time it is successful, one time is unsuccessful. If the phone is switched on, the service is working well.
I tried to use Httpclient with Http_client1.Execute(Http_krequest,2) and HttpUtils2 with Job.PostString. (Tried okhttp, okHttputils2 too) Also tried to use the #StartCommandReturnValue: android.app.Service.START_STICKY arguments but not helped.

I would like to send reliably the collected data while not use many energy.

Could you help me?

Thanks in advanced,

Istvan
 

Medexpert

Member
Licensed User
Longtime User
Thank you.
This works well.

The communication working but regularly get an error:
java.net.SocketTimeoutException: failed to connect to xxxxxxxxxxxxxxx (port 443) after 30000ms
or
java.net.SocketTimeoutException: connect timed out
or
java.net.SocketException: Software caused connection abort
The strangest error: java.net.UnknownHostException: Unable to resolve host "xxxxxxxxxxxxxx": No address associated with hostname
In this case I resend the request, but I get the error again. Another time (10minutes later) works fine.

If I check the host with webrowser I didn’t get any error works fine.
I tried it with Wifi and Mobile Internet too.

Have you got any suggestion?

Thanks,
Istvan
 
Upvote 0

lemonisdead

Well-Known Member
Licensed User
Longtime User
Have you got any suggestion?
Don't you think the device could stop any net connection while in the idle state ?
Perhaps should you try by waking it, changing the PhoneWakeState before trying to connect to the server
 
Upvote 0

Medexpert

Member
Licensed User
Longtime User
Yes, I use the PhoneWakeState.PartialLock command in Service_Start
Do I need wait some time after PartialLock?
 
Upvote 0

Medexpert

Member
Licensed User
Longtime User
I tried to ping the destination server. It is unsuccessful, try again 15 second: unsuccessful
If the phone is on, the ping is successful.
The Error: java.net.SocketTimeoutException: connect timed out and Error: java.net.SocketException: Software caused connection abort.
:(
 
Last edited:
Upvote 0

Medexpert

Member
Licensed User
Longtime User
I gaved the PartilLock command after Service started and tried to check the ping, and if unsuccessful then give the partiallock command again... not helped.
The GPS module successfuly wake up after PartialLock, but the wifi not.
If I use the KeepAlive command, it is working, but I don't want switch on the screen, and I think is to much power.
Is it any way to wake up the Network (Wifi and 3G) module?
 
Last edited:
Upvote 0

Medexpert

Member
Licensed User
Longtime User
Thanks.
Not working. :(
The Network problem only with Android 7 phones (I tried with 2 phones). On other Phones which have Android 5 or 6 Works well when I use the Phone PartialLock function.
Have you got any other idea?
 
Upvote 0

Medexpert

Member
Licensed User
Longtime User
I think I found the sulution. :)
I put the App into battery optimazation exception list and Works.

Can I disable an App optimazation from b4a code? Can I check the wheather App disabled or not? Can I open the Android form?
 
Upvote 0
Top