Android FTP seek Bar issue

Posted by Androi Developer on Stack Overflow See other posts from Stack Overflow or by Androi Developer
Published on 2012-10-18T10:57:51Z Indexed on 2012/10/18 11:00 UTC
Read the original article Hit count: 131

Filed under:

I am trying to Upload & Download file to server using FTP and Download File using HTTP i am able to do this, my problem is when i am trying to show seek bar with Upload status of file using ftp then it's not showing. In this attached image Using HTTP it's showing seekbar with Network spped like this i need to display seek bar & Network sppeed in FTP. Below code i wrote for FTP to upload file into server.

Code:--

// 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");

                        final long started = System.currentTimeMillis();
                        int size = input1.available();
                        //byte[] buffer = new byte[size];
                        byte dataByte[] = new byte[1024];
                        //input1.read(buffer);

                        //String data = "ZK DATA TESTER TEST DATA1sdfsdf";
                        String data = input1.toString();
                        System.out.println("dat value is........"+data);
                        final int lenghtOfFile = data.getBytes().length;
                        //final int lenghtOfFile = input1.getBytes().length;
                        System.out.println("length of file....."+lenghtOfFile);
                        ByteArrayInputStream in = new ByteArrayInputStream(
                                data.getBytes());

                         //toast("Uploading /test.txt"); 
                         //Toast.makeText(con,"File Size : " +data.getBytes().length + " bytes",Toast.LENGTH_SHORT).show();
                        //byte b[] = new byte[1024];

                        long total = 0;
                        long sleepingTime= 0;
                        System.out.println("started time --"+started);
                        updateUI(status, "Uploading");
                        while ((count = in.read(dataByte)) != -1)
                        {   
                     System.out.println("read value is...."+in.read(dataByte));
                            while (sleep1) {
                                Thread.sleep(1000);
                                System.out.println("ftp upload is in sleeping mode");
                                sleepingTime +=1000;    
                            }
                            System.out.println("Total count --"+count);  
                            total += count;

                            System.out.println("Only Total --"+total);

                            final int progress = (int) ((total * 100) / lenghtOfFile);
                            final long speed = total;
                            //duration = ((System.currentTimeMillis() - started)-sleepingTime) / 1000;

                            boolean result = ObjFtpCon.storeFile("/test.txt", input1);
                            //boolean result = ObjFtpCon.storeFile(map.get("file_address").toString()+"/test.txt", input1);

                        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");
                                    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);}*/
                        }
                        in.close();

© Stack Overflow or respective owner

Related posts about android