I want to restrict the opening of Browser on URL Click

0 votes

I have a simple url that i want to hit without opening the browser in mobile phones. I am clicking a button and that url needs to get hit, without the browser getting opened. I am not concerned with what is on that page i just want to load it. I basically need it for my arduino cum ethernet shield IOT project, wherein i am controlling my appliances with my android phone.I have looked at many places, tried a ton of things but nothing to seem to work for me somehow. 

Can anyone please help me here. 

Here is a snippet of what i am doing. The apk is generating without errors but the url is not getting hit somehow.

Thankyou

public void led1on(View view){
      try {
        URL u = new URL("http://172.17.27.173/?2");
        HttpURLConnection http = (HttpURLConnection) u.openConnection();
        http.connect();
    }catch (Exception e){
        e.getMessage();
        e.printStackTrace();
    }
}
Aug 7, 2018 in IoT (Internet of Things) by Matt
• 2,260 points

edited Aug 20, 2018 by Matt 362 views

1 answer to this question.

0 votes

You can call it as a web service and do nothing with the results. For example:

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.
    }
});

In order to see how to use the above code, you can take a look at here which has explained how to use the code for Android: http://loopj.com/android-async-http/

It is also possible to use some other library such as Apache Http client as well:https://hc.apache.org/

try {
        DefaultHttpClient httpClient = new DefaultHttpClient();
        HttpPost httpPost = new HttpPost(url);

        HttpResponse httpResponse = httpClient.execute(httpPost);
        HttpEntity httpEntity = httpResponse.getEntity();
        myContent = httpEntity.getContent();

    } catch ...
answered Aug 7, 2018 by anonymous2
• 4,260 points

Related Questions In IoT (Internet of Things)

0 votes
1 answer
0 votes
1 answer

How to use the data I receive from Azure IoT Hub?

The payload you receive will be a ...READ MORE

answered Aug 1, 2018 in IoT (Internet of Things) by DataKing99
• 8,130 points
646 views
0 votes
1 answer
0 votes
1 answer

MQTT : Connection lost on MQTT subscriber to Internet of Things Server

An invalid topic "matteo" seems to be causing the ...READ MORE

answered Oct 3, 2018 in IoT (Internet of Things) by Annie97
• 2,190 points
565 views
0 votes
1 answer

MQTT protocol connection error

Ok so you need two libraries to ...READ MORE

answered Jul 6, 2018 in IoT (Internet of Things) by anonymous2
• 4,260 points

reshown Jul 6, 2018 by Vardhan 552 views
0 votes
1 answer

IoT request response protocol

Based on your requirement of a light ...READ MORE

answered Jul 13, 2018 in IoT (Internet of Things) by anonymous2
• 4,260 points
336 views
0 votes
1 answer

Problem while disconnecting BLE device!

I think that's because of the way ...READ MORE

answered Jul 17, 2018 in IoT (Internet of Things) by nirvana
• 3,060 points
538 views
0 votes
1 answer
0 votes
1 answer

I want to perform Type Conversion of Date Type Value

Instead of returning return Long.toHexString(date.getTime()); Return following return Long.toHexString(date.getTime()/1000); As correctly ...READ MORE

answered Aug 3, 2018 in IoT (Internet of Things) by anonymous2
• 4,260 points
39 views
0 votes
1 answer