Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7782891
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T19:40:56+00:00 2026-06-01T19:40:56+00:00

I am currently creating a program that recursively searches through the SD card of

  • 0

I am currently creating a program that recursively searches through the SD card of the videos on an android phone, and then produces as hash for each of the videos.

Everything works fine, but when I try and create a progress bar, the progress bar doesn’t update, until the end.

So essentially progress bar’s progress appears to go from 0 to the max, but I can tell from log output that values are being sent to the progress bar to update it, the progress bar just isn’t upating.

My code is below:

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        progress = (ProgressBar) findViewById(R.id.progressBar1);
        text = (TextView) findViewById(R.id.tv1);
        Button btnStart = (Button) findViewById(R.id.btnStart);

        btnStart.setOnClickListener(new OnClickListener() {
            public void onClick(View v) {

                recursiveVideoFinder(new File("/sdcard"));
                String strDB3File = getFilesDir().getPath()
                        + "/VideoHashes.db3";
                sql3 = SQLiteDatabase.openDatabase(strDB3File, null,
                        SQLiteDatabase.CREATE_IF_NECESSARY);
                try {
                    String mysql = "CREATE TABLE videohashes (id INTEGER  NOT NULL PRIMARY KEY AUTOINCREMENT, path TEXT NOT NULL, hash TEXT NOT NULL, date TEXT NOT NULL, size INTEGER)";
                    sql3.execSQL(mysql);
                } catch (SQLiteException e) {
                    // TODO: handle exception
                }

                progress.setProgress(0);
                progress.setMax(myFiles.size());

                for (String path : myFiles) {
                    try {
                        String hash = getMD5Checksum(path);
                        ContentValues myInsertData = new ContentValues();
                        myInsertData.put("path", path);
                        myInsertData.put("hash", hash);
                        Date date = new Date();
                        myInsertData.put("date", dateFormat.format(date));
                        myInsertData.put("size", getFileSize(path));
                        sql3.insert("videohashes", null, myInsertData);
                        currVid++;
                        updateProgress();
                        Log.i("Progress", "CurrVid:" + currVid + "  Max:"
                                + progress.getMax());
                        text.append(currVid + " ");

                    } catch (Exception e) {
                        Log.i("File", "File not Found");
                    }
                }

                Cursor cur = sql3.query("videohashes", null, null, null, null,
                        null, null);
                cur.moveToFirst();
                while (!cur.isAfterLast()) {
                    /*
                     * ((TextView) findViewById(R.id.tv1)).append("\n" +
                     * cur.getString(1) + "\n" + cur.getString(2) + "\n" +
                     * cur.getString(3) + "\n" + cur.getString(4) + "\n");
                     */
                    cur.moveToNext();
                }
                cur.close();
            }
        });

    }

    public long getFileSize(String path) {
        File file = new File(path);
        return file.length();

    }

    private void recursiveVideoFinder(File _dir) {

        File[] files = _dir.listFiles();
        if (files == null) {
            return;
        }

        for (File currentFile : files) {
            if (currentFile.isDirectory()) {
                    recursiveVideoFinder(currentFile);
                continue;
            } else {
                for (String aEnd : getResources().getStringArray(
                        R.array.VideoExtensions)) {
                    if (currentFile.getName().endsWith(aEnd)) {

                        Log.d("PS:", currentFile.getPath().toString());

                        String videoFileName = currentFile.getPath().toString();
                        myFiles.add(videoFileName);

                    }
                }

            }
        }
    }

    // Code based off this example:
    // http://stackoverflow.com/questions/304268/getting-a-files-md5-checksum-in-java
    public static byte[] createCheckSum(String filename) throws Exception {
        InputStream fis = new FileInputStream(filename);

        byte[] buffer = new byte[1024];
        MessageDigest complete = MessageDigest.getInstance("MD5");
        int numRead;

        do {
            numRead = fis.read(buffer);
            if (numRead > 0) {
                complete.update(buffer, 0, numRead);
            }
        } while (numRead != -1);

        fis.close();
        // Return MD5 Hash
        return complete.digest();
    }

    public String getMD5Checksum(String filename) throws Exception {
        byte[] b = createCheckSum(filename);
        String result = "";

        for (int i = 0; i < b.length; i++) {
            result += Integer.toString((b[i] & 0xff) + 0x100, 16).substring(1);
        }
        return result;
    }

    public void updateProgress() {
        progress.setProgress(currVid);
        progress.invalidate();
        Log.i("Updating", "Updating Progress Bar");
    }
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-01T19:40:58+00:00Added an answer on June 1, 2026 at 7:40 pm

    Why do you keep all the processing code in Onclick(). That is not a good approach. Create an AsyncTask and use publishProgress to update your progressbar.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am currently creating a program that dynamically adds Image to a dockPanel every
I am currently creating a service which connects to a DAL and that can
I'm currently creating an MVC application that will likely to expand to include a
I'm creating a Win32 program that will be executed every time the computer turns
i'm currently creating a database program in java and i am a bit stuck
Basically I'm creating a forest fire program that depends on the wind / dryness
I'm currently creating a C# program which will be fetching some data over https
I am creating a program that displays several bases and the amount of troops
I am in the process of creating a Java program that goes on the
I'm currently creating a fullscreen Java application that will be like a kiosk application.

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.