2017-07-11 10 views
0

を使用して、zipファイルをダウンロードして、私はksoapのliabry.Iを使用して、サーバーからzipファイルをダウンロードしたいが、BASE64でデータを取得していますzipファイルとしてどのようにbase64に変換し、それを保存するという解決策を与えてくださいアンドロイドどのように石鹸liabrary

+0

あなたはこのような何かお読みください:https://stackoverflow.com/questions/19980307/stream-decoding-of-base64-dataを、変換しますBase64ファイルへのファイルストリーム。とにかく、より簡単にするために、より詳細といくつかのサンプルコードを提供してください – Panciz

答えて

-2

このコードは私をdownlad APKに助け、sdカードに保存する。また、これはあなたを助けるかもしれ
...

public class SaveInBackground extends AsyncTask<String,Integer,String> { 
    View v; 
    OutputValue ov; 
    Boolean isError= false; 

    public SaveInBackground(View v,OutputValue ov){ 
     this.v = v; 
     this.ov = ov; 

    } 
    @Override 
    protected void onPreExecute(){ 
     Message.setText("Downloading..."); 
     isToLoop =true; 
     new Thread(new Runnable() { 
      @Override 
      public void run() { 
       while (isToLoop) { 
        SystemClock.sleep(500); 
        runOnUiThread(new Runnable() { 
         @Override 
         public void run() { 
          int count = bar.getProgress() + 1; 
          bar.setProgress(count); 
         } 
        }); 
        if(isToLoop) 
         break; 
       } 
      } 
     }).start(); 
    } 

    @Override 
    protected void onProgressUpdate(Integer... values) { 
     bar.setProgress(values[0]); 
    } 

    @Override 
    protected String doInBackground(String... params) {InputStream input = null; 
     OutputStream output = null; 
     HttpURLConnection connection = null; 
     try { 
      URL url = new URL(Globle.Infosoft_serverLink.replace("/Service.asmx/","")+ov.url); 
      connection = (HttpURLConnection) url.openConnection(); 
      connection.connect(); 

      if (connection.getResponseCode() != HttpURLConnection.HTTP_OK) { 
       isError = true; 
       return "Server returned HTTP " + connection.getResponseCode() 
         + " " + connection.getResponseMessage(); 
      } 

      int fileLength = connection.getContentLength(); 
      input = connection.getInputStream(); 
      //publishProgress(80); 
      String path = Environment.getExternalStorageDirectory()+"/"+ov.Name+".apk"; 
      output = new FileOutputStream(path); 

      byte data[] = new byte[4096]; 
      long total = 0; 
      int count; 
      while ((count = input.read(data)) != -1) { 
       total += count; 
       if (fileLength > 0) // only if total length is known 
        publishProgress((int) (total * 100/fileLength)); 

       output.write(data, 0, count); 
      } 
      return path; 
     } 
     catch (Exception e) { 
      isError =true; 
      Snackbar.make(v,"Error while accessing storage.",Snackbar.LENGTH_LONG).show(); 
      return null; 
     }finally { 
      try { 
       if (output != null) 
        output.close(); 
       if (input != null) 
        input.close(); 
      } catch (IOException ignored) { 
      } 

      if (connection != null) 
       connection.disconnect(); 
     } 

    } 

    @Override 
    protected void onPostExecute(String result){ 
     if(!isError) { 
      Intent intent = new Intent(Intent.ACTION_VIEW); 
      intent.setDataAndType(Uri.fromFile(new File(result)), "application/vnd.android.package-archive"); 
      intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); 
      startActivity(intent); 
     } 
     Message.setText("Downloaded"); 
     reset(v); 
    } 

} 
+1

これは質問ではありません –

0
   byte[] bytes; 
       byte[] data = result.getBytes("UTF-8"); 
       File outputFile = new File(mediaStorageDir.getAbsolutePath(), + "filename.zip"); 
       new FileOutputStream(outputFile); 
       bytes = Base64.decode(data, Base64.DEFAULT); 
       File filepath = new File(Environment.getExternalStorageDirectory(), "Folder/" + "filename.zip"); 
       OutputStream pdffos = new FileOutputStream(filepath); 
       pdffos.write(bytes); 
       pdffos.flush(); 
       pdffos.close(); 
関連する問題