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,270 points

edited Aug 20, 2018 by Matt 6,252 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,240 points
I want to restrict the opening of Browser on URL Click | Edureka Community
<a href="http://www.go1i67zxaffm30fgy85414s598x675obs.org/">afvxstcwjz</a>
fvxstcwjz http://www.go1i67zxaffm30fgy85414s598x675obs.org/
[url=http://www.go1i67zxaffm30fgy85414s598x675obs.org/]ufvxstcwjz[/url]

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,250 points
2,131 views
+1 vote
1 answer
0 votes
1 answer

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

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

answered Oct 3, 2018 in IoT (Internet of Things) by Annie97
• 2,160 points
5,040 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,240 points

reshown Jul 6, 2018 by Vardhan 3,566 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,240 points
2,237 views
0 votes
1 answer

Problem while disconnecting BLE device!

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

answered Jul 18, 2018 in IoT (Internet of Things) by nirvana
• 3,090 points
4,131 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 4, 2018 in IoT (Internet of Things) by anonymous2
• 4,240 points
1,160 views
0 votes
1 answer
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP