小编Tol*_*eno的帖子

HTTP Async Downloader出错时自动恢复

我的应用程序中有一个异步下载器,但有时连接丢失,特别是当我在移动连接上并且文件很大(> 10 MB)时.有没有办法在下载停止时捕获,然后强制它继续完成下载的结果?

这是异步任务doInBackground:

protected String doInBackground(String... aurl) {
    int count;

    try {

        URL url = new URL(aurl[0]);
        URLConnection conexion = url.openConnection();
        // conexion.setRequestProperty("Range", "bytes=" + downloaded + "-");
        conexion.connect();

        int lenghtOfFile = conexion.getContentLength();
        pesoVideo = lenghtOfFile / 1048576;
        output = "/sdcard/" + folderString + "/" + nomeFile + ".mp3";
        InputStream input = new BufferedInputStream(url.openStream());
        OutputStream output = new FileOutputStream(
        VideoDownloaderBrowserActivity.this.output);

        byte data[] = new byte[1024];
        long total = 0;

        while ((count = input.read(data)) != -1) {
            total …
Run Code Online (Sandbox Code Playgroud)

java android download

7
推荐指数
1
解决办法
701
查看次数

标签 统计

android ×1

download ×1

java ×1