一個用于下載的android庫:android-downloader
一個用于下載的android庫。
主要特性如下:
1、使用簡單,最少只需要下載地址即可;
2、可以猜測下載任務名稱
3、自動設置下載路徑
4、支持斷點續傳
5、所有監聽返回的接口,例如onAdd等,都支持UI操作
DownloadManager downloadManager = new DownloadManager(this); DownloadTask task = new DownloadTask(this); task.setUrl("https://github.com/snowdream/android-autoupdate/raw/master/docs/test/android-autoupdater-v0.0.2-release.apk"); downloadManager.add(task, listener); //Add the task downloadManager.start(task, listener); //Start the task downloadManager.stop(task, listener); //Stop the task if you exit your APP. private DownloadListener listener = new DownloadListener<Integer, DownloadTask>() { /** * The download task has been added to the sqlite. * <p/> * operation of UI allowed. * * @param downloadTask the download task which has been added to the sqlite. */ @Override public void onAdd(DownloadTask downloadTask) { super.onAdd(downloadTask); Log.i("onAdd()"); list.add(downloadTask); Log.i(""+downloadTask); adapter.notifyDataSetChanged(); } /** * The download task has been delete from the sqlite * <p/> * operation of UI allowed. * * @param downloadTask the download task which has been deleted to the sqlite. */ @Override public void onDelete(DownloadTask downloadTask) { super.onDelete(downloadTask); Log.i("onDelete()"); } /** * The download task is stop * <p/> * operation of UI allowed. * * @param downloadTask the download task which has been stopped. */ @Override public void onStop(DownloadTask downloadTask) { super.onStop(downloadTask); Log.i("onStop()"); } /** * Runs on the UI thread before doInBackground(Params...). */ @Override public void onStart() { super.onStart(); Log.i("onStart()"); } /** * Runs on the UI thread after publishProgress(Progress...) is invoked. The * specified values are the values passed to publishProgress(Progress...). * * @param values The values indicating progress. */ @Override public void onProgressUpdate(Integer... values) { super.onProgressUpdate(values); ((DownloadTaskAdapter) getListAdapter()).notifyDataSetChanged(); Log.i("onProgressUpdate"); } /** * Runs on the UI thread after doInBackground(Params...). The specified * result is the value returned by doInBackground(Params...). This method * won't be invoked if the task was cancelled. * * @param downloadTask The result of the operation computed by * doInBackground(Params...). */ @Override public void onSuccess(DownloadTask downloadTask) { super.onSuccess(downloadTask); Log.i("onSuccess()"); } /** * Applications should preferably override onCancelled(Object). This method * is invoked by the default implementation of onCancelled(Object). Runs on * the UI thread after cancel(boolean) is invoked and * doInBackground(Object[]) has finished. */ @Override public void onCancelled() { super.onCancelled(); Log.i("onCancelled()"); } @Override public void onError(Throwable thr) { super.onError(thr); Log.i("onError()"); } /** * Runs on the UI thread after doInBackground(Params...) when the task is * finished or cancelled. */ @Override public void onFinish() { super.onFinish(); Log.i("onFinish()"); } };
下載:
下載最新的jar
或者通過maven
com.github.snowdream.android.app downloader 1.0
或者通過gradle
compile 'com.github.snowdream.android.app:downloader:1.0'
項目主頁:http://www.baiduhome.net/lib/view/home/1389106104812
本文由用戶 jopen 自行上傳分享,僅供網友學習交流。所有權歸原作者,若您的權利被侵害,請聯系管理員。
轉載本站原創文章,請注明出處,并保留原始鏈接、圖片水印。
本站是一個以用戶分享為主的開源技術平臺,歡迎各類分享!