我知道这个问题是重复的,我没有得到自满的答案.我正在使用Android系统DownloadManager从网络下载文件,它可以正常下载文件.
private DownloadManager downloadManager;
Button start;
Button pause;
Button resume;
Run Code Online (Sandbox Code Playgroud)
初始化上面的所有按钮
downloadManager = (DownloadManager) getSystemService(DOWNLOAD_SERVICE);
Uri Download_Uri = Uri
.parse("uri");
DownloadManager.Request request = new DownloadManager.Request(
Download_Uri);
Run Code Online (Sandbox Code Playgroud)
然后它已被放入下载队列.当转弯即将开始下载
我的问题是,是否有任何简单的方法来暂停下载和恢复下载
downloadManager.pause();
downloadManager.resume();
Run Code Online (Sandbox Code Playgroud)
提前致谢.
有谁知道如何请求字节范围以及HTTP请求?我希望通过请求下载中断的字节范围并从getContent()读取其InputStream来促进在我们的应用程序中恢复下载.
我尝试迭代标题,但它们是null.来源如下.
import java.io.IOException;
import java.io.InputStream;
import org.apache.http.Header;
import org.apache.http.HttpEntity;
import org.apache.http.HttpResponse;
import org.apache.http.client.ClientProtocolException;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.impl.client.DefaultHttpClient;
import android.util.Log;
/**
* @author Kevin Kowalewski
*
*/
public class DownloadClient {
DefaultHttpClient httpClient;
HttpGet httpGet;
HttpResponse httpResponse;
HttpEntity httpEntity;
InputStream httpInputStream;
private static String LOG_TAG = DownloadClient.class.getName();
public DownloadClient(){
httpClient = new DefaultHttpClient();
httpGet = new HttpGet("http://cachefly.cachefly.net/100mb.test");
for (Header header : httpGet.getAllHeaders()){
Log.d(LOG_TAG, "--> Header: " + header);
}
Log.d(LOG_TAG, "--> Header size is: " + httpGet.getAllHeaders().length);
try {
httpResponse …Run Code Online (Sandbox Code Playgroud)