2012-05-16 4 views
0

파일 암호화 및 암호 해독 앱을 개발 중이며 파일 암호화 및 암호 해독의 진행률 막대를 약간 보여줍니다. 진행률 표시 줄을 구현해야합니다. 어떻게해야합니까? 아래 코드를 참조하십시오.android에서 진행률 표시 줄 구현

public void main(String[] args) throws Exception 
     { 

     // File to decrypt. 
     filename = "/file.enc"; 

     String password = "codecodecode"; 

     inFile = new FileInputStream(new File(Environment.getExternalStorageDirectory()+ filename)); 
     outFile = new FileOutputStream(new File(Environment.getExternalStorageDirectory()+ filename + ".txt")); 

     PBEKeySpec keySpec = new PBEKeySpec(password.toCharArray()); 
     SecretKeyFactory keyFactory = 
      SecretKeyFactory.getInstance("PBEWithMD5AndDES"); 
     SecretKey passwordKey = keyFactory.generateSecret(keySpec); 

     // Read in the previouly stored salt and set the iteration count. 

     byte[] salt = new byte[8]; 
     inFile.read(salt); 
     int iterations = 100; 

     PBEParameterSpec parameterSpec = new PBEParameterSpec(salt, iterations); 

     // Create the cipher and initialize it for decryption. 

     Cipher cipher = Cipher.getInstance("PBEWithMD5AndDES"); 
     cipher.init(Cipher.DECRYPT_MODE, passwordKey, parameterSpec); 


     byte[] input = new byte[64]; 
     int bytesRead; 
     while ((bytesRead = inFile.read(input)) != -1) 
     { 
     byte[] output = cipher.update(input, 0, bytesRead); 
     if (output != null) 
      outFile.write(output); 
     } 

     byte[] output = cipher.doFinal(); 
     if (output != null) 
     outFile.write(output); 

     inFile.close(); 
     outFile.flush(); 
     outFile.close(); 
    } 

답변

0

확인 진행률 표시 줄에있는 튜토리얼 : https://developer.android.com/guide/topics/ui/dialogs.html#ShowingAProgressBar

또한 "두 번째 스레드와 예해서 ProgressDialog"이 - 확인 반갑습니다.

이런 종류의 것들에 대해서는 AsyncTask을 사용하는 것이 좋습니다. UI 스레드에서 진행 상황 업데이트 이벤트를 게시하기위한 지원 기능이 내장되어 있습니다.