1

I have a device(ESP8266) which i have programmed in order to turn on/off my lights. It works like this: i open my browser and go on http://192.168.100.3/on and it turns on. To turn it off, i type http://192.168.100.3/off . I now want to make an android application that will do that for me when I click a button. I am being able to do it using this code:




    Intent i = new Intent(Intent.ACTION_VIEW);
    i.setData(Uri.parse("http://192.168.100.3/on"));
    startActivity(i);

However, this technique is opening the browser. I do not want that. I want it to run the url without opening the browser.

Thank you for your time,

Maths_nerd

Maths_Nerd
  • 13
  • 1
  • 4
  • 4
    have a look at: https://developer.android.com/reference/java/net/HttpURLConnection.html – Henry Jun 18 '17 at 11:07

1 Answers1

1

Try this WebService Method.

AsyncHttpClient client = new AsyncHttpClient();
client.get("http://172.17.27.173/yourpage", params, new AsyncHttpResponseHandler() {
@Override
public void onSuccess(String response) { // 200 OK
    // Do nothing
}
@Override
public void onFailure(int statusCode, Throwable error, String content) { // Response not 200
{
    // Some troubleshooting, etc.
}
});

More Explain Here