/** 初始化DownloadManager */ public synchronized void init(DownloaderManagerConfiguration configuration) { FileDownloader.init(configuration.getContext(), configuration.getOkHttpClientCustomMaker()); FileDownloader.getImpl().bindService(); ILogger.DEBUG = configuration.isDebug(); FileDownloadLog.NEED_LOG = ILogger.DEBUG; this.mConfiguration = configuration; this.mExtFieldMap = configuration.getDbExtField(); mDbController = new FileDownloaderDBController( configuration.getContext(), configuration.getDbVersion(), mExtFieldMap, configuration.getDbUpgradeListener()); mAllTasks = mDbController.getAllTasks(); mConnectListenerList = new ArrayList<>(); mListenerManager = new ListenerManager(); mAutoRetryTimes = configuration.getAutoRetryTimes(); mHeaders = configuration.getHeaders(); // 设置下载保存目录 if (!StringUtils.isEmpty(configuration.getDownloadStorePath())) { FileDownloadUtils.setDefaultSaveRootPath(configuration.getDownloadStorePath()); } mWaitQueue = new LinkedList<>(); mDownloadingList = Collections.synchronizedList(new ArrayList<FileDownloaderModel>()); mDownloadManager = this; ShellUtils.execCommand("chmod 777 " + configuration.getDownloadStorePath(), false); }
@Override public void onCreate() { super.onCreate(); // 下面这句为了测试,正常使用的时候不用添加 FileDownloadLog.NEED_LOG = BuildConfig.DEBUG; // 不耗时,做一些简单初始化准备工作,不会启动下载进程 FileDownloader.init(this); // FileDownloader.getImpl().bindService(); }