title: Show ProgressDialog when copying a file from gallery
body: <p><strong>Currently</strong></p>
  
  <p>I open the gallery with an <code>Intent</code>, the user can then pick a video from the gallery after which the file is copied to a specified folder. This all works fine.</p>
  
  <p>I would like to display a <code>ProgressBar</code> right after the user selects a video (in the Gallery) and then <code>progresbar.dismiss</code> once the file is done copying.</p>
  
  <p>Here is similar questions, but no answers (nothing that worked):</p>
  
  <ul>
  <li><a href="https://stackoverflow.com/questions/24060623/how-to-display-a-dialog-over-gallery-screen-in-android">How to display a dialog over gallery screen in android?</a></li>
  <li><a href="https://stackoverflow.com/questions/24036184/how-to-load-progress-bar-circle-after-user-selects-image-from-gallery-in-android">Progress Bar Circle after user selects image from gallery in android?</a></li>
  </ul>
  
  <p>This is how I call the gallery:</p>
  
  <pre><code>public void selectVideoFromGallery()
  {
  
      Intent intent;
      if(android.os.Environment.getExternalStorageState().equals(android.os.Environment.MEDIA_MOUNTED))
      {
          intent = new Intent(Intent.ACTION_PICK, android.provider.MediaStore.Video.Media.EXTERNAL_CONTENT_URI);
      }
      else
      {
          intent = new Intent(Intent.ACTION_PICK, android.provider.MediaStore.Video.Media.INTERNAL_CONTENT_URI);
      }
  
      intent.setType("video/*");
      intent.setAction(Intent.ACTION_GET_CONTENT);
      intent.putExtra("return-data", true);
      startActivityForResult(intent,SELECT_VIDEO_REQUEST);
  }
  </code></pre>
  
  <p>I have tried <code>progressbar.show();</code> here (above) but obviously it will start showing before the video is selected.</p>
  
  <p>here is my <code>OnActivityResult</code>:</p>
  
  <pre><code>@Override
  protected void onActivityResult(int requestCode, int resultCode, Intent data)
  {
      if(requestCode == SELECT_VIDEO_REQUEST &amp;&amp; resultCode == RESULT_OK)
      {
          if(data.getData()!=null)
          {
  
  
              //copy file to new folder
              Uri selectedImageUri = data.getData();
              String sourcePath = getRealPathFromURI(selectedImageUri);
  
              File source = new File(sourcePath);
  
              String filename = sourcePath.substring(sourcePath.lastIndexOf("/")+1);
  
              File destination = new File(Environment.getExternalStorageDirectory(), "MyAppFolder/CopiedVids/"+filename);
              try
              {
                  FileUtils.copyFile(source, destination);
              }
              catch (IOException e)
              {
                  e.printStackTrace();
              }
  
  
              sendBroadcast(new Intent(Intent.ACTION_MEDIA_SCANNER_SCAN_FILE, Uri.fromFile(destination)));
  
  
              Toast.makeText(getApplicationContext(),"Stored at:  "+"---"+sourcePath+"----"+"with name:   "+filename, Toast.LENGTH_LONG).show();
  
  
  
          }
          else
          {
              Toast.makeText(getApplicationContext(), "Failed to select video" , Toast.LENGTH_LONG).show();
          }
      }
  }
  </code></pre>
  
  <p>I have tried <code>progressbar.show();</code> here (above) but the dialog never get displayed.</p>
  
  <p>My guess is to do this with <code>AsyncTask</code>, but then where to call <code>AsyncTask</code></p>
  
  <p>and here is my ProgressDialog:</p>
  
  <pre><code>ProgressDialog progress;
  
   @Override
  protected void onCreate(Bundle savedInstanceState) {
      super.onCreate(savedInstanceState);
      setContentView(R.layout.activity_main);
  
      progress = new ProgressDialog(this);
      progress.setMessage("Copying Video....");
      progress.setProgressStyle(ProgressDialog.STYLE_HORIZONTAL);
      progress.setIndeterminate(true);
  
  }
  </code></pre>
  
  <p><strong>My Question</strong></p>
  
  <p>I need clarification on how this can be achieved, will I be able to do this without <code>AsyncTask</code> and if not, where should <code>AsyncTask</code> be called from?</p>