0

I'm going to upload multiple photo/video using LoopJ AndroidAsyncHttp to server. My problem is i need to add cancel button for each of the photo and allow the user to cancel the uploading. May i know anyone got the solution for this? or any others better example for me to refer? My Code as below :-

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();
                        }
    }
Stephane Landelle
  • 6,990
  • 2
  • 23
  • 29
micky
  • 235
  • 2
  • 4
  • 16

1 Answers1

2

Very simple dear-

1)just send one by one image on server and then create a popup window for send next image or cancel.

2)In your database or where you have images just set flag 0 and 1. So you can easily make query for send image on server which one is pending.

3)And when you got successes response from server change your flag value in database.

Manish Srivastava
  • 1,649
  • 2
  • 15
  • 23