0

我想知道我是否可以打开它但不打开android浏览器,我只需要它访问:(假装这是ip)http;//91.91.91.91:2228?1,它会在我的arduino上触发动作兆。我试图让它只是用这段代码来做到这一点

onclick(Intent websiteIntent = new Intent(Intent.ACTION_VIEW);
    Uri uri = Uri.parse("http;//91.9.91.91:?1");
    websiteIntent.setData(uri);
    startActivity(websiteIntent);)

但我不知道如何让它这样做

4

1 回答 1

5

HttpClient 将允许您在应用程序中调用任意 URL:

DefaultHttpClient client = new DefaultHttpClient();
HttpGet request = new HttpGet("http;//91.9.91.91:?1");
HttpResponse response = client.execute(request);

不过不要忘记包裹在 try catch 中。

编辑:

new Thread(){
    public void run(){
        try{
            DefaultHttpClient client = new DefaultHttpClient();
            HttpGet request = new HttpGet("http;//91.9.91.91:?1");
            HttpResponse response = client.execute(request);
        }catch(Exception e){
            // Handle the exception
            e.printStackTrace();
        }
    }
};
于 2013-02-18T23:57:25.787 回答