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 8754167
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T13:34:04+00:00 2026-06-13T13:34:04+00:00

In my android project i need to display seekbar and network speed(With how much

  • 0

In my android project i need to display seekbar and network speed(With how much speed the file is Uploading/Downloading from server using FTP Protocol). In my situation when i try to upload a file from emulator sdcard then it’s showing the speed and seekbar at the end when the file is stored in the server, but my requirement is i need to show sheekbar and network speed continuously while the file is uploading into server. I am not understand where i did wrong in my code. Below is my code for file upload into ftp server:

Thanks In Advance.

    @Override
    protected String doInBackground(String... arg0) {
        int count = 0;
        FTPClient ObjFtpCon = new FTPClient();
        //Toast.makeText(con, "FTPasync doInBackground() is called" ,Toast.LENGTH_SHORT).show();
        try {
            runOnUiThread(new Runnable() {
                public void run() {

                    bar.setProgress(0);
                    //real_time.setText(0 + " secs");
                    test_avg.setText(0+ " kbps");                       
                    //peak.setText(0+" kbps");
                }
            });
            updateUI(pp, R.drawable.pause);
            //ObjFtpCon.connect("ftp.customhdclips.com");
            ObjFtpCon.connect("ftp."+map.get("url").toString());
            updateUI(status, "Connecting");

            //if (ObjFtpCon.login("fstech@customhdclips.com", "fstech123")) {
            if (ObjFtpCon.login(map.get("username").toString(), map.get("password").toString())) {  
                updateUI(status, "Connected");
                ObjFtpCon.enterLocalPassiveMode(); // important!
                ObjFtpCon.cwd("/");// to send the FTP CWD command to the server, receive the reply, and return the reply code. 


                //if (mode == 0) {
                if(Integer.parseInt((map.get("oprn").toString()))== 0){  // Download File Using FTP Protocol
                    System.out.println("download test is called");
                    File objfile = new File(Environment.getExternalStorageDirectory() + File.separator + "/logo.png");

                    objfile.createNewFile();
                    FileOutputStream objFos = new FileOutputStream(objfile);
                    boolean blnresult = ObjFtpCon.retrieveFile("/logo.png", objFos);
                    objFos.close();
                    if (blnresult) {
                        // toast("Download succeeded");
                        // toast("Stored at : " +
                        // objfile.getAbsolutePath());
                    }

                    //***********************************************************

                    /*
                    File objfile = new File(
                            Environment.getExternalStorageDirectory()
                                    + File.separator + "/test.txt");

                    // System.out.println("total" + objfile.getTotalSpace() + " bytes");

                    objfile.createNewFile();
                    FileOutputStream objFos = new FileOutputStream(objfile);
                    boolean blnresult = ObjFtpCon.retrieveFile("/test.txt",
                            objFos);
                    objFos.close();
                    if (blnresult) {
                        System.out.println("download in ftp is successful");
                        // toast("Download succeeded");
                        // toast("Stored at : " +
                        // objfile.getAbsolutePath());
                    }*/
                } 

                else {
                    // Upload
                    System.out.println("upload test is called");
                    //Toast.makeText(con, "upload FTP test is called", Toast.LENGTH_SHORT).show();
                    //ContextWrapper context = null;
                    //assetManager= context.getAssets();

                    assetManager = getResources().getAssets();
                    input1 = assetManager.open("hello.txt");
                    long total = 0;
                    long sleepingTime= 0;

                    final long started = System.currentTimeMillis();
                    int size = input1.available();
                    byte[] buffer = new byte[size];
                    byte dataByte[] = new byte[1024];
                    //byte dataByte[] = new byte[(int)((CharSequence) input1).length()];
                    //input1.read(buffer);
                    //final int lenghtOfFile = data.getBytes().length;
                    final int lenghtOfFile = input1.toString().getBytes().length;
                    System.out.println("length of file....."+lenghtOfFile);
                    ByteArrayInputStream byteArrayIS = new ByteArrayInputStream(input1.toString().getBytes());
                    System.out.println("ByteArrayIS value is...."+byteArrayIS);
                    System.out.println("started time --"+started);
                    updateUI(status, "Uploading");
                    while ((count = byteArrayIS.read(dataByte)) != -1)
                    {   
                        System.out.println("read value is...."+byteArrayIS.read(dataByte));
                        while (sleep1) {
                            System.out.println("While Loop Sleep1 is Called");
                            Thread.sleep(1000);
                            sleepingTime +=1000;    
                        }

                        total += count;
                        System.out.println("Total Value IS:: "+total);
                        System.out.println("Count Value Is:: "+count);
                        final int progress = (int) ((total * 100) / lenghtOfFile);
                        System.out.println("Progress Value IS::" + progress);
                        final long speed = total;
                        //duration = ((System.currentTimeMillis() - started)-sleepingTime) / 1000; --- When using this line then it's not updating Avarage

                        boolean result = ObjFtpCon.storeFile("/test.txt", input1);
                        //boolean result = ObjFtpCon.storeFile(map.get("file_address").toString()+"/test.txt", input1); --- When using this line then it's not updating Status

                        duration = ((System.currentTimeMillis() - started)-sleepingTime) / 1000;
                        runOnUiThread(new Runnable() {
                            public void run() {     
                                    //bar.setProgress(progress);
                                    // trans.setText("" + progress);
                                    //duration = ((System.currentTimeMillis() - started)-sleepingTime) / 1000;
                                    //duration = ((System.currentTimeMillis() - started)-sleepingTime) / 1000;  
                                    //real_time.setText(duration + " secs");
                                    if (duration != 0) {
                                        test_avg.setText((((speed / duration)*1000)*0.0078125)  + " kbps");
                                        bar.setProgress(progress);
                                        /*if (pk <= (speed / duration) / 1024) {
                                    pk = (speed / duration) / 1024;
                                }*/
                                        if (pk <= ((speed / duration)*1000)*0.0078125) {
                                            pk = (long)(((speed / duration)*1000)*0.0078125);
                                        }
                                        //peak.setText(pk + " kbps");
                                    }
                                }
                        });

                        //in.close();
                        if (result) {
                            updateUI(status, "Uploaded");
                            // toast("Uploading succeeded");
                            // toast("Uploaded at /test.txt");
                            //duration = ((System.currentTimeMillis() - started)-sleepingTime) / 1000;
                            System.out.println("curreent time..... "+System.currentTimeMillis());
                            System.out.println("started time --"+started);
                            System.out.println("sleep tome...."+sleepingTime);
                            System.out.println("duration is....."+duration);
                            /*runOnUiThread(new Runnable() {
                            public void run() {
                                bar.setProgress(progress);
                                // trans.setText("" + progress);
                                //duration = ((System.currentTimeMillis() - started)-sleepingTime) / 1000;

                                real_time.setText(duration + " secs");
                                if (duration != 0) {
                                    test_avg.setText((speed / duration) / 1024
                                            + " kbps");
                                    if (pk <= (speed / duration) / 1024) {
                                        pk = (speed / duration) / 1024;
                                    }
                                    peak.setText(pk + " kbps");
                                }
                            }
                        });*/
                        }
                        /*while(!result){Thread.sleep(1000);}*/
                    }
                    byteArrayIS.close();
                }
            }

            else{
                System.out.println("password entered is incorrect");
                //Toast.makeText(con, "Username or/and password is incorrect", Toast.LENGTH_SHORT).show();
            }
        } 
        catch (Exception e) {
            e.printStackTrace();
            // toast(e.getLocalizedMessage());
        }

        try {
            ObjFtpCon.logout();
            ObjFtpCon.disconnect();
        } 
        catch (IOException e) {
            e.printStackTrace();
            // toast(e.getLocalizedMessage());
        }
        return null;
    }    
  • 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-13T13:34:05+00:00Added an answer on June 13, 2026 at 1:34 pm

    Since you’re calling doInBackground(), I assume you’re subclassing AsyncTask. If so, why aren’t you using publishProgress and onProgressUpdate? runOnUiThread doesn’t execute immediately unless you’re already on the UI Thread, and because you’re in doInBackground() you’re in a background thread, not the UI Thread. There’s a possibility that runOnUiThread() isn’t actually running until doInBackground() is over. In comparison, publishProgress and onProgressUpdate are specifically designed to report progress from the background thread.

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

Sidebar

Related Questions

I've got a single Android project which I need to build many .apk's from.
I want to export signed apk file from my Android Project with a terminal
How do I display a TextArea for my android project? From xml, the only
My android app project need to add a new function of saving the click
I'm doing a Get and Post method for an android project and I need
I have an Android project I've inherited from another developer. The original code was
I want to display the current revision number of my Android project to the
I am making one project where i need to display Home page and when
I am working on an Android project in that i need to send the
I want to execute Python/ Ruby/ Javascript scripts in an Android project. I need

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.