android下载框架,支持单线程和多线程断点下载。
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
libs init Sep 2, 2015
res init Sep 2, 2015
src/com/gh/ghdownload Remove unused folder Sep 2, 2015
.classpath init Sep 2, 2015
.gitignore init Sep 2, 2015
.project init Sep 2, 2015
AndroidManifest.xml init Sep 2, 2015
README.md Update README.md Dec 25, 2015
ic_launcher-web.png init Sep 2, 2015
proguard-project.txt init Sep 2, 2015
project.properties init Sep 2, 2015

README.md

GHDownload

一、How to use?

Step1:

String url = "http://gh-game.oss-cn-hangzhou.aliyuncs.com/1434794302961350.apk";
DownloadEntry entry = new DownloadEntry(url);
entry.name = "x三国.apk";

Step2: To start a downloading task:

DownloadManager.getInstance(MainActivity.this).add(entry);

To pausea downloading task:

DownloadManager.getInstance(MainActivity.this).pause(entry);

To resume downloading task:

DownloadManager.getInstance(MainActivity.this).resume(entry);

To resume cencel task:

DownloadManager.getInstance(MainActivity.this).cancel(entry);

Step3: If you want to receive process information of downloading task, you should add observer in current Class,for example, in MainActivity:

(1)Create a datawatcher to receive notification.

       private DataWatcher dataWatcher = new DataWatcher() {

		@Override
		public void onDataChanged(DownloadEntry data) {
			entry = data;
			showText.setText(entry.toString());
		}
	};

(2)Add observer.

    @Override
    protected void onResume() {
        super.onResume();
		DownloadManager.getInstance(this).addObserver(dataWatcher);
    }

(3)Remove observer.

    @Override
    protected void onPause() {
        super.onPause();
        DownloadManager.getInstance(this).removeObserver(dataWatcher);
    }

二、Set download config

In DownloadConfig.java You can set max downloading task and max downloading threads.

If you set max_download_threads to 1,it will use FileOutputStream instead of RandomAccessFile, which is faster. Otherwise, it will use RandomAccessFile.

private int max_download_tasks = 3;
private int max_download_threads = 3;
public static String DOWNLOAD_PATH = Environment.getExternalStorageDirectory() + File.separator +
    		"gh-download" + File.separator;

##备注: (1)该下载框架使用了ormlite框架

(2)如果使用生成的ghdownloadv1.2.jar作为引用的jar包,注意要把ormlite的jar包也一起引用

(3)在AndroidManifest.xml中要添加如下service:

<service android:name="com.gh.ghdownload.core.DownloadService" >