0

I've searched a while, and I could find some posts, answer, but none of them worked with me.

I have an Arduino board that receives an URL as argument to switch pins, etc.

E.g: http:// 192.168.0.20/staticpin_12_1

All I want to do is to build an Android apk that, when pressed a button, do this http post request to android, without opening the browser.

I know there is a way to do that, but I'm having an 'App Crash' everytime. Could you guys help me out?

Note: I've added already the uses permissions to access the INTERNET @ Manifest.xml. My device's version of Android is 4.1.2, and I'm using eclipse as IDE.

  • 3
    `App Crash` is not a good debug report. Tell us what you've tried and exactly what's failing. – Sotirios Delimanolis Sep 19 '13 at 14:37
  • 2
    Please, not another NetworkOnMainThreadException's question!!! – Selvin Sep 19 '13 at 14:39
  • I don't understand why this question was put on hold - the only possible good reason would be "duplicate" but since it's not it should be re-opened. This is definitely NOT "off-topic". @Nickollas Aranha you might want to add the code that preforms the HTTP request to the question. – Nir Alfasi Sep 20 '13 at 16:56

1 Answers1

1

I'm not a mobile developer but I ran into the same problem when I "played" with it: the App crashes since you're trying to preform a synchronized HTTP request from the (current) thread of your app which means that the execution needs to stop and wait for the server's response. This kind of sync HTTP calls is not allowed since Gingerbread if I'm not mistaken.

You should make an async request and handle the result using postExecute().

Community
  • 1
  • 1
Nir Alfasi
  • 53,191
  • 11
  • 86
  • 129