2013-10-29 31 views
0

我打算使用LoopJ AndroidAsyncHttp上传多张照片/视频到服务器。我的问题是我需要为每张照片添加取消按钮,并允许用户取消上传。我可以知道任何人都有解决这个问题吗?或任何其他更好的例子给我参考? 我的代码如下: -使用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(); 
         } 
    } 

回答

2

很简单dear-

1)只是在服务器发送一个由一个图像,然后创建发送下一个图像的弹出窗口或取消。

2)在你的数据库或你有图像只需设置标志0和1.因此,你可以很容易地查询 在服务器上发送图像哪一个正在等待。

3)当你得到成功从服务器响应改变你的数据库中的标志值。

+0

感谢之间。任何其他解决方案可以终止AsyncHttpClient? – micky

+0

就我所知,没有别的办法。我认为这是最好的方式。如果你认为我的回答很有用,请为其他人开绿灯。 –