Android暂停和恢复上传

时间:2014-03-27 11:54:31

标签: android file-upload

我想为我的上传组件创建暂停和恢复系统。到目前为止,我可以使用以下代码直接并连续地将视频上传到ym远程服务器:

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();
}

如何暂停上传,保存进度。做我想做的事(比如杀死应用程序)然后当我重新启动它时,恢复它并继续上传丢失的部分?

谢谢你的宝贵帮助。

1 个答案:

答案 0 :(得分:1)

我终于找到了实现这一目标的方法,而不是从Github到Kienco

以下是他的代码的链接:https://github.com/kienco/android-simpl3r