我想爲我的上傳組件創建一個暫停和恢復系統。到目前爲止,我能夠直接連續視頻上傳到YM遠程服務器用下面的代碼:Android暫停和恢復上傳
private void uploadVideo(String videoPath) throws Exception
{
HttpClient httpclient = new DefaultHttpClient();
HttpPost httppost = new HttpPost(SEVER_ENDPOINT);
FileBody filebodyVideo = new FileBody(new File(videoPath));
StringBody title = new StringBody("Filename: " + videoPath);
StringBody description = new StringBody("Short description");
MultipartEntity reqEntity = new MultipartEntity();
reqEntity.addPart("videoFile", filebodyVideo);
reqEntity.addPart("title", title);
reqEntity.addPart("description", description);
httppost.setEntity(reqEntity);
if (DEBUG) Log.d(TAG, "executing request " + httppost.getRequestLine());
HttpResponse response = httpclient.execute(httppost);
HttpEntity resEntity = response.getEntity();
if (DEBUG) Log.d(TAG, response.getStatusLine());
if (resEntity != null)
{
if (DEBUG) Log.d(TAG, EntityUtils.toString(resEntity));
resEntity.consumeContent();
}
httpclient.getConnectionManager().shutdown();
}
我怎麼會暫停上傳,保存進度。做我想做的任何事情(如殺死應用程序),然後當我重新啓動它,恢復它,並繼續上傳缺少的部分?
Tahnks爲您提供寶貴的幫助。
首先,你需要檢查,如果你的服務器有這樣的斷點續傳的API。如果是的話,你應該使用這個API來做你想做的事情,如果沒有,沒有什麼可以幫助你。 –