마스터Q&A 안드로이드는 안드로이드 개발자들의 질문과 답변을 위한 지식 커뮤니티 사이트입니다. 안드로이드펍에서 운영하고 있습니다. [사용법, 운영진]

안드로이드 FTPClient 다운로드 업로드시 얼만큼 진행되었는지 퍼센트로 표시하는법

0 추천
안드로이드 FTPClient 다운로드 업로드시 얼만큼 진행되었는지 퍼센트로 표시하는법

    private void fileDownloadtest(final String strPath, final String strItem, final int i) {
            VsrcFilePath = strPath;
            VdesFilePath = FileUtil.FTPCLINET_LOCAL_DOWNLOAD + strItem;
            mHandler.sendEmptyMessageDelayed(Percent,3000);
        Thread mThread = new Thread(new Runnable() {
            
            @Override
            public void run() {
                try {
                    
                    boolean res = FTPManager.getInstance().ftpDownload(strPath + strItem,                     FileUtil.FTPCLINET_LOCAL_DOWNLOAD + strItem, i); //다운로드 하는곳

 

Thread를 써서  다운로드 받으면서 핸드러 쪽에서 퍼센트를 3초에 한번씩 출력하게 만들고 싶은데

핸들러에서 UpDownPercent2이 함수를 호출해서 실행하는데

100퍼센트가 되기전에 불러오면 오류가 나고 100퍼센트 되고나서 불러오면 100퍼센트라고 잘 나오는데

어떻게 해야 중간에 값들을 불러올수 있을까요?

    String UpDownPercent2(String srcFilePath, String desFilePath, int downPos) {
        // TODO Auto-generated method stub
        FTPFile[] Fa = null;
        
            // 퍼센트 용량 불러오기
            try {
                Fa = mFTPClient.listFiles(srcFilePath);
            } catch (IOException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }
            int a2 = (int) Fa[downPos-1].getSize();
            String b = FileUtil.txtFileImformation(desFilePath);
            int b2 = (int) Long.parseLong(b);
            double percent = (double)((double)b2/(double)a2) * 100;
                //Float percent = (float) ((a2/b2)*100);
            String dispPattern = "0.##";
            DecimalFormat form = new DecimalFormat(dispPattern);
            percent = (int)Float.parseFloat(form.format(percent));
            String per = String.valueOf(percent);
            //this.totalBytesTransferred = totalBytesTransferred;
                    if(a2==b2)
                    {
                        PercentEnd = true;
                    }
                    return per;
                    
    }
익명사용자 님이 2016년 3월 2일 질문

답변 달기

· 글에 소스 코드 보기 좋게 넣는 법
· 질문에 대해 추가적인 질문이나 의견이 있으면 답변이 아니라 댓글로 달아주시기 바랍니다.
표시할 이름 (옵션):
개인정보: 당신의 이메일은 이 알림을 보내는데만 사용됩니다.
스팸 차단 검사:
스팸 검사를 다시 받지 않으려면 로그인하거나 혹은 가입 하세요.
...