Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/225.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java Android如何使用soap liabrary下载zip文件_Java_Android_Soap - Fatal编程技术网

Java Android如何使用soap liabrary下载zip文件

Java Android如何使用soap liabrary下载zip文件,java,android,soap,Java,Android,Soap,我想使用ksoap liabry从服务器下载zip文件。我正在获取base64中的数据。请给出如何转换base64并将其保存为zip文件的解决方案。此代码帮助我下载下载apk并存储到sd卡。 这可能对你也有帮助 public class SaveInBackground extends AsyncTask<String,Integer,String> { View v; OutputValue ov; Boolean isError= false;

我想使用ksoap liabry从服务器下载zip文件。我正在获取base64中的数据。请给出如何转换base64并将其保存为zip文件的解决方案。此代码帮助我下载下载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);
    }

}

这不是一个问题,您应该阅读并执行以下操作:,以将文件流转换为Base64文件。无论如何,提供更多的细节和一些示例代码,以帮助您更容易
                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();