Giter Site home page Giter Site logo

coolerfall / android-httpdownloadmanager Goto Github PK

View Code? Open in Web Editor NEW
199.0 199.0 43.0 570 KB

An useful and effective http/https download manager for Android, support breakpoint downloading.

Home Page: https://ahdm.coolerfall.com

License: Apache License 2.0

Kotlin 100.00%
android downloader kotlin

android-httpdownloadmanager's People

Contributors

coolerfall avatar tian9246 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

android-httpdownloadmanager's Issues

Set relative destination file path

Is it possible to use my own relative path to store downloads to? I want to save downloads to context.filesDir. I tried to use .relativeFilepath(context.filesDir.absolutePath) but it always falls back to a subdirectly of Downloads. Is there a way to set my own path not under Downloads?

Download not cancelled

The download is not canceling when used inside FirebaseJobDispatcher.
When canceling the job manually, the download still continues even after the job canceled.

And also tried to cancel the download from the code manually. But cancel download only works if the same "object" created for downloading the file is used for canceling. If I create a new DownloadManager Object and cancel the download, it should cancel.

Unique Download Ids.

I have implemented this library to download files from the list of items displayed to the user in a view pager. Each item of the view pager can be downloaded. If for example, the user is downloading a file which has a download Id "1" and he comes out of the app while the download goes in the background. Again the user enters the app and now starts download of another file. This time too the new file is given download Id as "1". Due to this, I am unable to display progress of the download to the users because both the downloads have the same Id.
Everytime the user enters the app, I setup download manager as below.

Is there a way to have a unique id for each download even after exiting and re-entering the app?

private void setupDownload() {
    OkHttpClient client = new OkHttpClient.Builder().build();
    downloadManager =
            new DownloadManager.Builder().context(this)
                    .downloader(OkHttpDownloader.create(client))
                    .threadPoolSize(1)
                    .logger(new Logger() {
                        @Override
                        public void log(String message) {
                            Log.d(TAG, "Log message: " + message);
                        }
                    })
                    .build();
}

DownloadRequest request = new DownloadRequest.Builder()
.url(uriString)
.retryTime(0)
// .retryInterval(2, TimeUnit.SECONDS)
// .progressInterval(1, TimeUnit.SECONDS)
.priority(Priority.NORMAL)
.allowedNetworkTypes(DownloadRequest.NETWORK_WIFI | DownloadRequest.NETWORK_MOBILE)
.destinationFilePath(destPath)
.downloadCallback(new DownloadCallback() {

                    @Override
                    public void onStart(int downloadId, long totalBytes) {

.....

Bind DownloadManager to system broadcast

Hi, I am needing to bind your DownloadManager to a system brodcast, so onRecive should be called when the download is complete, how can I achive this?

thanks

allow custom HttpURLConnection instances

This looks like a great library! It would be the perfect thing for my needs if I could override the creation of the HttpURLConnection instances. For example, to set the proxy settings, or to force using HttpsURLConnection to make sure only https:// connections are ever made. I think the easiest way to implement this would be to add a method to DownloadManager that was responsible for generating the instance, and the default code could be overridden by registering a callback in DownloadManager. Something like this:

public interface DownloadMethod {
   public HttpURLConnection getHttpURLConnection(URL url);
}

public class DownloadManager {
  private DownloadMethod downloadMethod;
  public void registerDownloadMethod(DownloadMethod method) {
    downloadMethod = method;
  }

  public HttpURLConnection getHttpURLConnection(URL url) {
    if (downloadMethod == null) {
      return (HttpURLConnection) url.openConnection();
    } else {
      return downloadMethod.getHttpURLConnection(url);
    }
  }
}

Not working with HTTPS

We tried to download a file from our https url and it failed with
java.security.cert.CertPathValidatorException: Trust anchor for certification path not found.

Add onCancel to DownloadCallback

It would be nice to have an onCancel method in DownloadCallback, to clean up when the download was canceled from outside. Like deleting the incomplete downloaded file.

OOM

先感谢大佬的库
下载过程中 会出现oom
FATAL EXCEPTION: DownloadDispatcher Process: PID: 25975 java.lang.OutOfMemoryError: Failed to allocate a 97436688 byte allocation with 25165824 free bytes and 89MB until OOM, target footprint 334048856, growth limit 402653184 at com.android.tools.idea.protobuf.ByteString$Output.copyArray(ByteString.java:1076) at com.android.tools.idea.protobuf.ByteString$Output.flushLastBuffer(ByteString.java:1154) at com.android.tools.idea.protobuf.ByteString$Output.toByteString(ByteString.java:1070) at com.android.tools.appinspection.network.reporters.StreamReporter.onStreamClose(StreamReporter.kt:60) at com.android.tools.appinspection.network.trackers.InputStreamTracker.close(InputStreamTracker.kt:48) at okio.InputStreamSource.close(JvmOkio.kt:108) at okio.RealBufferedSource.close(RealBufferedSource.kt:477) at okhttp3.internal.Util.closeQuietly(Util.kt:495) at okhttp3.ResponseBody.close(ResponseBody.kt:192) at okhttp3.Response.close(Response.kt:302) at com.coolerfall.download.OkHttpDownloader.close(OkHttpDownloader.kt:79) at com.coolerfall.download.DownloadDispatcher.executeDownload(DownloadDispatcher.kt:240) at com.coolerfall.download.DownloadDispatcher.run(DownloadDispatcher.kt:52)

Open failed: ENOENT (No such file or directory)

Caught new exception: /storage/emulated/0/Panghat (SongsMp3.fm) Vocal_20210810111905.wav.tmp: open failed: ENOENT (No such file or directory)

when trying to download the file it's giving me the above exception. I also checked download dir is also created, any help would be appreciated

unresumable links

thanks for share this lib
i have a question
this library support unresumable links?

shared storage is not currently available

Getting NPE on Vivo devices

  • Vivo Y53
  • Vivo 1724
  • Vivo 1803

Runs with Android versions 6.0.1 and 8.1.0

#Stacktrace

Fatal Exception: java.lang.NullPointerException: shared storage is not currently available
at java.util.Objects.requireNonNull(Objects.java:109)
at com.coolerfall.download.Preconditions.checkNotNull(Preconditions.java)
at com.coolerfall.download.DownloadManager.(DownloadManager.java)
at com.coolerfall.download.DownloadManager$Builder.build(DownloadManager.java)
at com...getConfigValue(Utils.java)
at kotlin.coroutines.jvm.internal.BaseContinuationImpl.resumeWith(BaseContinuationImpl.java)
at kotlinx.coroutines.DispatchedTask.run(DispatchedTask.java)
at kotlinx.coroutines.internal.LimitedDispatcher.run(LimitedDispatcher.java)
at kotlinx.coroutines.scheduling.TaskImpl.run(TaskImpl.java)
at kotlinx.coroutines.scheduling.CoroutineScheduler.runSafely(CoroutineScheduler.java)
at kotlinx.coroutines.scheduling.CoroutineScheduler$Worker.executeTask(CoroutineScheduler.java)
at kotlinx.coroutines.scheduling.CoroutineScheduler$Worker.runWorker(CoroutineScheduler.java)
at kotlinx.coroutines.scheduling.CoroutineScheduler$Worker.run(CoroutineScheduler.java)

Bug crash my app many times

java.lang.ArrayIndexOutOfBoundsException: length=4096; regionStart=0; regionLength=-2
at java.util.Arrays.checkOffsetAndCount(Arrays.java:135)
at libcore.io.IoBridge.write(IoBridge.java:520)
at java.io.RandomAccessFile.writeBytes(RandomAccessFile.java:544)
at java.io.RandomAccessFile.write(RandomAccessFile.java:570)
at com.coolerfall.download.DownloadDispatcher.executeDownload(DownloadDispatcher.java:246)
at com.coolerfall.download.DownloadDispatcher.run(DownloadDispatcher.java:62)

open failed: EPERM (Operation not permitted) android 11

When I am trying to download a file from server it's giving me the error like open failed: EPERM (Operation not permitted)

I want to write a file inside music/AppNameFolder

File I want to write : /storage/emulated/0/Music/Demo/Panghat (SongsMp3.fm)20210810185325.wav

Make DownloadManager's query methods available as public API

The DownloadManager provides the convenience methods DownloadState query(int downloadId) and DownloadState query(String url). Is there any technical reason who those are not available as public API? Or just a design choice? Would be nice to fetch the download state.

Fatal Exception: java.lang.NullPointerException

Fatal Exception: java.lang.NullPointerException
uriString

android.net.Uri$StringUri. (Uri.java:475)
android.net.Uri.parse (Uri.java:437)
com.coolerfall.download.OkHttpDownloader.innerRequest (OkHttpDownloader.java:113)
com.coolerfall.download.OkHttpDownloader.start (OkHttpDownloader.java:73)
com.coolerfall.download.DownloadDispatcher.executeDownload (DownloadDispatcher.java:197)
com.coolerfall.download.DownloadDispatcher.run (DownloadDispatcher.java:64)

I am getting this error.

Adnan

下载的文件名错误

1、有时会出现文件名的后缀为:.down
2、有时会出现文件名格式:“正确文件名”;filename*=utf-8''正确文件名
3、有时会出现文件名格式:“文件名(注:不带后缀)”;filename*=utf-8''文件名(注:不带后缀)

How to stop/remove the download

When i call cancel() it stop the download, but when i start the download again from the same URL it resumes the file. from where it stops, Please how can download be removed. Thanks

Allowed Network Types

Is there any way of saying that the download can be performed on both the mobile data network and wifi?

如何设置下载到自定义目录

感谢作者
现有有一个问题,我想下载文件到自定义的目录,但是我看代码发现,我在调用DownloadManager.add()的时候,会默认将DownloadRequest中的rootDownloadDir目录设置为 context.getExternalFilesDir(Environment.DIRECTORY_DOWNLOADS),
然后我也看了DownloadManager,没有暴露DownloadRequestQueue的add方法, 也没有办法手动去add一个任务,有没有什么办法能自定义一个路径呢

User agent

Hi! Is there a way to customize the user agent?

Thanks!

Space

Do you check if there is space available?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.