FileDownloader
FileDownloader copied to clipboard
多次将app从最近任务划出,重启后无法启动下载服务
暂停时 int taskSize = FileDownloader.getImpl().pause(downloadID); 返回0
重新启动时 打印日志如下
07-26 16:39:57.845 29369-29369/ D/FileDownloader.FileDownloadServiceUIGuard: bindStartByContext MyApplication
07-26 16:39:57.846 29369-29369/ W/ContextImpl: Calling a method in the system process without a qualified user: android.app.ContextImpl.bindService:1763 android.content.ContextWrapper.bindService:539 com.liulishuo.filedownloader.services.BaseFileServiceUIGuard.bindStartByContext:156 com.liulishuo.filedownloader.services.BaseFileServiceUIGuard.bindStartByContext:126 com.liulishuo.filedownloader.FileDownloadServiceProxy.bindStartByContext:112
07-26 16:39:57.850 29369-29369/ W/ContextImpl: Calling a method in the system process without a qualified user: android.app.ContextImpl.startService:1699 android.content.ContextWrapper.startService:516 com.liulishuo.filedownloader.services.BaseFileServiceUIGuard.bindStartByContext:157 com.liulishuo.filedownloader.services.BaseFileServiceUIGuard.bindStartByContext:126 com.liulishuo.filedownloader.FileDownloadServiceProxy.bindStartByContext:112
07-26 16:39:57.903 29369-29369/ D/FileDownloader.DownloadTask: setPath /sdcard/update.zip
07-26 16:39:57.913 29369-29369/ D/FileDownloader.DownloadTask: setListener com.jiang.test.presenter.SystemUpdatePresenter$NotificationListener@3a8ec18b
07-26 16:39:57.914 29369-29369/ V/FileDownloader.DownloadTaskHunter: call start Url[https://api.test.net/file/?file=423&sn=19b24c6b&md5=c8ade1e28ba9a3feee8b400833d064b4], Path[/sdcard/update.zip] Listener[com.jiang.test.presenter.SystemUpdatePresenter$NotificationListener@3a8ec18b], Tag[null]
07-26 16:39:57.956 29369-29369/ V/FileDownloader.DownloadTaskHunter: the task[2055569966] has been into the launch pool.
07-26 16:39:57.963 29369-29498/ V/FileDownloader.FileDownloadEventPool: setListener event.service.connect.changed
07-26 16:39:57.964 29369-29498/ D/FileDownloader.LostServiceConnectedHandler: Waiting for connecting with the downloader service... 2055569966
07-26 16:39:57.964 29369-29498/ D/FileDownloader.FileDownloadServiceUIGuard: bindStartByContext MyApplication
07-26 16:39:57.964 29369-29498/ W/ContextImpl: Calling a method in the system process without a qualified user: android.app.ContextImpl.bindService:1763 android.content.ContextWrapper.bindService:539 com.liulishuo.filedownloader.services.BaseFileServiceUIGuard.bindStartByContext:156 com.liulishuo.filedownloader.services.BaseFileServiceUIGuard.bindStartByContext:126 com.liulishuo.filedownloader.FileDownloadServiceProxy.bindStartByContext:112
07-26 16:39:57.967 29369-29498/ W/ContextImpl: Calling a method in the system process without a qualified user: android.app.ContextImpl.startService:1699 android.content.ContextWrapper.startService:516 com.liulishuo.filedownloader.services.BaseFileServiceUIGuard.bindStartByContext:157 com.liulishuo.filedownloader.services.BaseFileServiceUIGuard.bindStartByContext:126 com.liulishuo.filedownloader.FileDownloadServiceProxy.bindStartByContext:112
07-26 16:39:57.972 29369-29498/ D/FileDownloader.DownloadTaskHunter: free the task 2055569966, when the status is 10
代码如下
public void pauseDownload() {
if (downloadID != 0) {
int taskSize = FileDownloader.getImpl().pause(downloadID);
if(taskSize==0){
FileDownloader.getImpl().stopForeground(true);
FileDownloader.getImpl().unBindService();
}
downloadID = 0;}
@Override
public void downloadPackage() {
if(checkBattery()&&checkStorage()&&checkNetwork()){
PrefUtil.setPrefInt(context.getApplicationContext(),DEVICE_STATUS,DEVICE_STATUS_OK);
String url = PrefUtil.getPrefString(context.getApplicationContext(),OTA_PACKAGE_DOWNLOAD_URL,"");
if(downloadID==0){
FileDownloader.getImpl().bindService();
downloadID = FileDownloader.getImpl().create(PrefUtil.getPrefString(context.getApplicationContext(),OTA_PACKAGE_DOWNLOAD_URL,""))
.setPath(OTA_PACKAGE_STORAGE_PATH)
.setAutoRetryTimes(3)
.setSyncCallback(false)
.setListener(new NotificationListener(new FileDownloadNotificationHelper<NotificationItem>()))
.start();
}
}
页面销毁时回调
@Override
public void onViewDestroy() {
pauseDownload();
view = null;
if(subscription2!=null&&subscription!=null){
subscription.unsubscribe();
subscription2.unsubscribe();
}
}
服务一直没起来
查了往期issue #306
在filedownloader.properties中定义 process.non-separate=true 后得到解决
可以在你的主页面中调用bindService