我想知道我是否可以打开它但是没有打开android浏览器,我只需要它来访问:(假装这是ip)http; // 91.91.91.91:2228?1,它会触发动作在我的arduino mega上。我试图用这段代码来做到这一点
onclick(Intent websiteIntent = new Intent(Intent.ACTION_VIEW);
Uri uri = Uri.parse("http;//91.9.91.91:?1");
websiteIntent.setData(uri);
startActivity(websiteIntent);)
但我不知道如何做到这一点
答案 0 :(得分:5)
HttpClient允许您在应用中调用任意URL:
DefaultHttpClient client = new DefaultHttpClient();
HttpGet request = new HttpGet("http;//91.9.91.91:?1");
HttpResponse response = client.execute(request);
不要忘记尝试捕获。
编辑:
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();
}
}
};