xSpartanCx
xSpartanCx

Reputation: 311

Android app code to access webstite

I'm looking to write an android app that will call a fun little script I made on my computer. when I open the script in my web browser, the computer will run the "beep" command. How would I do this from inside an android app so that when I press a button it'll call the website and beep my comuputer? I've tried this, but it didn't seem to work for me.

HttpGet httpget = new HttpGet(
    "http://www.blah.com/beep.php");

More info: The code I'm running on the server:

beeping!
<?php
shell_exec("beep -f 2000 -r 3 -l 100 -d 20"); ?>

I'm running the app that has a button that calls the beep method.

public class MainActivity extends Activity {

@Override
  protected void onCreate(Bundle savedInstanceState) {
   super.onCreate(savedInstanceState);
   setContentView(R.layout.activity_main);
 }

@Override
 public boolean onCreateOptionsMenu(Menu menu) {
 // Inflate the menu; this adds items to the action bar if it is present.
 getMenuInflater().inflate(R.menu.main, menu);
 return true;
} //here is the error that says i need to remove this token

new Thread(new Runnable() {
  public void run(){
    try{
      HttpClient httpclient = new DefaultHttpClient();

      HttpGet httpget = new HttpGet(
        "http://www.blah.com/beep.php");
    }
    catch(Exception e){
      throw e;
  }}
}).start();
} //here is the error to insert } to complete classbody

Upvotes: 0

Views: 382

Answers (1)

Alexander
Alexander

Reputation: 48272

new Thread(new Runnable() {
public void run() {
    try {
    HttpClient httpclient = new DefaultHttpClient();

    HttpGet httpget = new HttpGet(
        "http://www.blah.com/beep.php");
    HttpResponse response = httpclient.execute(httpget);
    } catch(Exception x) {
        ...
    }}
}).start();

Upvotes: 1

Related Questions