0

I am trying to make an API call to the address: apps.smilemachine.com/smilefactory/api/v1.0/speedup. I just want to execute the url (above) so that it increments the machine and changes the speed value stored at Smilemachine.com? Nothing special I just need to execute the url as if you were typing it into the address bar in any browser?

Has anyone got any advice for this or code snippets?

My current code just opens the browser, please find below:

increasespeed.setOnClickListener(new View.OnClickListener() {

    public void onClick(View view) {
        Intent increasespeed = new Intent(null, Uri.parse("http://apps.smilemachine.com/smilefactory/api/v1.0/speedup"));
                startActivity(increasespeed);

    }
});
1
  • Thanks for the head ups Rawkode
    – Joshua
    Nov 27, 2012 at 23:55

1 Answer 1

1

Just get it via an HTTP connection:

URL url = new URL("http://apps.smilemachine.com/smilefactory/api/v1.0/speedup");
HttpURLConnection connection = (HttpURLConnection)url.openConnection();
connection.setRequestMethod("GET");
connection.connect();
2
  • Thanks PearsonArtPhoto, do you know of an alternative way to achieve the same thing, this seems to need endless try catch statements?
    – Joshua
    Nov 27, 2012 at 23:54
  • 1
    Endless try catch statements? If you're not that fussed about catching accurate exceptions, wrap all of it with try { .... } catch (Exception e) { // Log this }
    – Rawkode
    Nov 27, 2012 at 23:56

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.