title: Calling publishProgress from another method in Android
body: <p>I am trying to download a file from my server in Android and updating the progress.. </p>
  
  <p>On Async method in background I am calling a method that will download the file to my SD card now I would like update the progress hence trying publishProgress("" + progressvalue); which I am not able access from this method. How do I access the publishProgress?</p>
  
  <p>Here is what I am trying:</p>
  
  <pre><code>private class FileDownloader extends AsyncTask&lt;String, String, Void&gt; {
  
          @Override
          protected Void doInBackground(String... param) {
              downloadFileToSdCard(param[0], "File" + counter + ".mp4");
              return null;
          }
  
          protected void onProgressUpdate(String... values)
          {
              Log.d("ANDRO_ASYNC", values[0]);
          }
  }
  </code></pre>
  
  <p>downloadFileToSdCard method looks like this:</p>
  
  <pre><code>private void downloadImagesToSdCard(String downloadUrl, String fileName)]
  {
          FileOutputStream fos;
          InputStream inputStream = null;
  
          try {
              URL url = new URL(downloadUrl);
              String sdCard = Environment.getExternalStorageDirectory().toString();
              File myDir = new File(sdCard, "AppDownload");
              if (!myDir.exists()) {
                  myDir.mkdir();
              }
  
              String fname = fileName;
              File file = new File(myDir, fname);
              if (file.exists())
                  file.delete();
  
              URLConnection ucon = url.openConnection();
              final String contentLengthStr=ucon.getHeaderField("content-length");
  
              int lenghtOfFile = Integer.valueOf(contentLengthStr);
  
              HttpURLConnection httpConn = (HttpURLConnection) ucon;
              httpConn.setRequestMethod("GET");
              httpConn.connect();
              inputStream = httpConn.getInputStream();
  
              fos = new FileOutputStream(file);
              byte[] buffer = new byte[1024];
              int bufferLength = 0;
              long total = 0;
              int progress = 0;
              while ((bufferLength = inputStream.read(buffer)) &gt; 0)
              {
  
                  total += bufferLength;
                  int progress_temp = (int) total * 100 / lenghtOfFile;
                  publishProgress("" + progress_temp);
                  if (progress_temp % 10 == 0 &amp;&amp; progress != progress_temp)
                  {
                      progress = progress_temp;
                  }
                  fos.write(buffer, 0, bufferLength);
                  int downloadedSize = Integer.valueOf(contentLengthStr);
              }
              inputStream.close();
              fos.close();
              Log.e("Value", "File Saved in sdcard..");
          } catch (IOException io) {
              inputStream = null;
              fos = null;
              io.printStackTrace();
          } catch (Exception e) {
              e.printStackTrace();
          } finally {
  
          }
      }
  </code></pre>
  
  <p>Can somebody help me fix this? Thanks!</p>