Q:

Calling publishProgress from another method in Android

I am trying to download a file from my server in Android and updating the progress.. 
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?
Here is what I am trying:
private class FileDownloader extends AsyncTask<String, String, Void> {

        @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]);
        }
}

downloadFileToSdCard method looks like this:
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)) > 0)
            {

                total += bufferLength;
                int progress_temp = (int) total * 100 / lenghtOfFile;
                publishProgress("" + progress_temp);
                if (progress_temp % 10 == 0 && 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 {

        }
    }

Can somebody help me fix this? Thanks!

A:

Triy this:
keep you function inside into AsyncTask Class
     private class FileDownloader extends AsyncTask<String, String, Void> {

            @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]);
            }

            private void downloadImagesToSdCard(String downloadUrl, String fileName)
            { 
               //Publish Progress calling code
            }
}

