Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android http server not accessible from other devices on network intermittently

I'm using NanoHTTPD to present a web server in an android app. I'm using a wifi lock to keep the network alive, and a CPU lock to keep the cpu awake, and keeping it running via a foreground service so that it should never die.

What i'm finding is that it'll be accessible from other devices for half an hour, and then not accessible for half an hour. Whenever it becomes inaccessible, I can open safari on the android device and browse to 0.0.0.0:30000 and verify that the server is indeed running. And i also check to make sure the wifi is connected which it appears to be.

Any suggestions of where to look?

like image 465
Chris Avatar asked Dec 02 '15 08:12

Chris


1 Answers

I don't know the exact reason why it's stop working. There are ways to keep service running but try this line of code in your activity onCreate if this can help you out

getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
like image 172
Qamar Avatar answered Oct 27 '22 04:10

Qamar