我正在寻找一个Android应用程序,它将调用我在计算机上制作的有趣小脚本。当我在网络浏览器中打开脚本时,计算机将运行“beep”命令。我如何从Android应用程序内部执行此操作,以便当我按下按钮时它会调用网站并发出嘟嘟声我的计算机?我试过这个,但它似乎对我不起作用。
HttpGet httpget = new HttpGet(
"http://www.blah.com/beep.php");
更多信息: 我正在服务器上运行的代码:
beeping!
<?php
shell_exec("beep -f 2000 -r 3 -l 100 -d 20"); ?>
我正在运行的应用程序有一个调用beep方法的按钮。
公共类MainActivity扩展了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
答案 0 :(得分: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();