我正在将图像文件上传到android中的服务器。 我想知道上传何时完成。是否有任何方法可以知道这一点。 如果在上传完成时自动调用的android中有任何状态。 或如何检查此状态。上传结束时检测
Q
上传结束时检测
0
A
回答
2
如果您使用HttpClient.execute(),这是一个同步的方法 - 它返回一旦上传完成。
编辑:有没有异步HTTP客户端在Android上,据我所知。对于非阻塞上传,使用HttpClient是工作者线程,并使用Handler.post(Runnable)在主线程中处理完成。
EDIT2:异步HTTP看起来是这样的:
final Handler Ha = new Handler(); //Used to post the results back to the main thread
new Thread(new Runnable(){
public void run()
{
HttpPost pr = new HttpPost(MyURL);
pr.setEntity(MyUploadData);
//More request setup...
HttpResponse Resp = new DefaultHttpClient().execute(pr);
//Process response here... detect errors, for one thing
Ha.post(new Runnable(){
public void run()
{
//This executes back in the main thread!
}
});
}
}).start();
提供一些代码,请。 – 2011-04-19 16:58:35