我将使用LoopJ AndroidAsyncHttp将多张照片/视频上传到服务器。我的问题是我需要为每张照片添加取消按钮并允许用户取消上传。我可以知道有人有解决方案吗?或者任何其他更好的例子供我参考?我的代码如下:-
public static void putMultipleUploadPhoto(String server,
final ProgressBar progressbarb, final String FileType, final TextView textviewb, final String FolderPath, final int itemcount, final int position)
{
final String url = "http://" + server + ":" + server.Photo_Upload;
File myFile = new File(data);
final RequestParams params = new RequestParams();
try {
params.put("data", myFile);
} catch (FileNotFoundException e) {
e.printStackTrace();
}
final AsyncHttpClient client = new AsyncHttpClient();
final int totalprogress1 = 0;
try {
client.post(url,params,new AsyncHttpResponseHandler() {
public void onStart() {
// Initiated the request
progressbarb.setProgress(0);
}
@Override
public void onProgress(int position, int length) {
// TODO Auto-generated method stub
int totalprogress;
totalprogress = (position*100)/length;
progressbarb.setProgress(totalprogress);
super.onProgress(position, length);
}
@Override
public void onSuccess(String response) {
String regex = "n"; // Only this line is changed.
String split[] = response.split(regex, 2);
if (split[0] != null)
{
String status[]=split[0].split("\t");
if (status[0].equals("true"))
{
textviewb.setVisibility(View.VISIBLE);
textviewb.setText("Success");
if (status[0].equals("false"))
{
textviewb.setText("Fail";
textviewb.setVisibility(View.VISIBLE);
}
}
}
@Override
public void onFailure(Throwable e, String response) {
textviewb.setVisibility(View.VISIBLE);
textviewb.setText("Fail");
}
});
} catch (Exception e) {
// TODO: handle exception
e.printStackTrace();
}
}
很简单,亲爱的-
1)只需在服务器上逐个发送图像,然后创建一个弹出窗口以发送下一张图像或取消。
2)在您的数据库中或有图像的地方,只需设置标志 0 和 1。因此,您可以轻松进行查询对于在服务器上发送图像,哪个处于挂起状态。
3)当您从服务器获得成功响应时,更改数据库中的标志值。