android执行远程地址,就会报android.os.Net..... 这个原因是网络操作不能在主线程进行,必须新建一个进程
new Thread(new Runnable(){
@Overridepublic void run() {
try {
HttpClient httpClient = new DefaultHttpClient();
HttpGet httpRequest = new HttpGet("http://"
+ ipaddr.getIp() + ":"
+ ipaddr.getPort()
+ "/kzServer/CanelComputer");
HttpResponse httpResponse;
httpResponse = httpClient.execute(httpRequest);
} catch (ClientProtocolException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
}
}).start();
Toast.makeText(KzActivity.this, "成功!", Toast.LENGTH_LONG)
.show();
这样操作可以不用打开浏览器就可以触发远程服务器
版权声明:本文为博主原创文章,未经博主允许不得转载。