2013-05-20 15 views
0

我期待着編寫一個android應用程序,它將調用我在我的電腦上製作的一個有趣的小腳本。當我在Web瀏覽器中打開腳本時,計算機將運行「beep」命令。我將如何從android應用程序內部執行此操作,以便當我按下按鈕時,它會打電話給網站併發出我的計算機嘟嘟聲?我試過這個,但它似乎並沒有爲我工作。訪問webstite的Android應用程序代碼

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

更多信息: 我在服務器上運行的代碼:

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

我跑,有一個按鈕調用蜂鳴方法的應用。

公共類MainActivity擴展活動{

@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 

回答

1
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(); 
+0

我有一個致命的狀態異常,當我試圖運行這個... – xSpartanCx

+0

http://pastebin.com/CXGgnnr2 – xSpartanCx

+0

不要從同新線程看我的更新 –