Open githubZYQ opened 4 years ago
我也是遇到了相同的问题,根本没有任何回调,而且下载的文件大小全都一样。
progress回调和pending回调中totalBytes一直是0;所以一直没有正确的进度显示;
我的解决方案是自己单独使用HttpURLConnection 获取文件总大小,然后保存下来用这个值去计算进度。
有一个问题值的注意的是,不是所有的文件都无法获取大小,像这个我们服务器https://www.bus365.com/public/phoneClient/BUS365.apk 获取不到,但是豌豆荚https://www.wandoujia.com/apps/2236553/download/dot?ch=detail_normal_dl 就可以。
很有可能是文件服务器对文件进行了压缩导致的。
URL url = new URL(apkUrl); HttpURLConnection urlcon = (HttpURLConnection) url.openConnection(); //处理下载读取长度为-1 问题 urlcon.setRequestProperty("Accept-Encoding", "*"); urlcon.connect(); int l = urlcon.getContentLength(); int total = (int) l;
如题:使用的1.7.7的库,在低版本手机使用正常,在9.0和10.0手机调用下载时无任何回调,日志如下: 2020-05-08 11:31:30.269 3200-3200/com.yt.driver D/FileDownloader.c: setPath /storage/emulated/0/Android/data/com.yt.driver/cache/倚天司机端.apk 2020-05-08 11:31:30.270 3200-3200/com.yt.driver D/FileDownloader.c: setListener com.yt.driver.app.view.UpdateDialog$4@596b098 2020-05-08 11:31:30.270 3200-3200/com.yt.driver V/FileDownloader.d: call start Url[https://www.bus365.com/public/phoneClient/BUS365.apk], Path[/storage/emulated/0/Android/data/com.yt.driver/cache/倚天司机端.apk] Listener[com.yt.driver.app.view.UpdateDialog$4@596b098], Tag[null] 2020-05-08 11:31:30.275 3200-11753/com.yt.driver V/FileDownloader.f: setListener event.service.connect.changed 2020-05-08 11:31:30.275 3200-3200/com.yt.driver V/FileDownloader.d: the task[887050704] has been into the launch pool. 2020-05-08 11:31:30.277 3200-11753/com.yt.driver D/FileDownloader.e: not found filedownloader.properties 2020-05-08 11:31:30.278 3200-11753/com.yt.driver I/FileDownloader.e: init properties 1 load properties: http.lenient=FALSE; process.non-separate=FALSE; download.min-progress-step=65536; download.min-progress-time=2000; download.max-network-thread-count=3; file.non-pre-allocation=FALSE; broadcast.completed=FALSE; download.trial-connection-head-method=FALSE 2020-05-08 11:31:30.280 3200-11753/com.yt.driver D/FileDownloader.z: Waiting for connecting with the downloader service... 887050704 2020-05-08 11:31:30.281 3200-11753/com.yt.driver D/FileDownloader.o: bindStartByContext MyApplication 2020-05-08 11:31:30.293 3200-11753/com.yt.driver D/FileDownloader.d: free the task 887050704, when the status is 10 ,