我想從服務器上下載的zip文件使用KSOAP liabry.I我用base64獲取數據請給出解決方案,如何爲base64轉換並保存爲zip文件的Android如何用肥皂liabrary
0
A
回答
-2
此下載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);
}
}
+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();
相關問題
- 1. 如何插入用肥皂值的Android
- 2. 的MySQL到Android用肥皂
- 3. 如何從肥皂
- 4. 用肥皂水
- 5. 如何處理肥皂結果在Android ..?
- 6. 如何獲得帶肥皂泡的肥皂信封python
- 7. 肥皂XML解析Android中
- 8. Android:肥皂原始錯誤
- 9. Web服務Android肥皂
- 10. 共存肥皂1.1和肥皂1.2
- 11. 肥皂肥皂數字簽名
- 12. 如何正確設置標題爲肥皂肥皂客戶端
- 13. Android的ListView使用肥皂呼籲
- 14. 從android中調用肥皂web服務
- 15. 肥皂內WebRequest
- 16. BeSimple肥皂庫
- 17. $ {}東西肥皂
- 18. Broadsoft在肥皂
- 19. 如何開始使用肥皂ui
- 20. 如何在javascript中使用肥皂
- 21. 如何使用zend肥皂生成wsdl
- 22. 如何啓用肥皂擴展
- 23. 的肥皂變量
- 24. symfony的2 +肥皂
- 25. 肥皂從Node.js的
- 26. SugarCRM的肥皂get_entry_list
- 27. 如何調用WCF HTTPS從肥皂Android版的WSHttpBinding
- 28. 如何最好地使用Android的PHP肥皂?
- 29. Android中的複雜類型肥皂
- 30. 呼叫肥皂WSDL web服務的Android
你應該讀做這樣的事情:https://stackoverflow.com/questions/19980307/stream-decoding-of-base64-data,轉換一個到Base64文件的文件流。無論如何提供更多的細節和一些示例代碼,以幫助您更輕鬆 – Panciz