Пример #1
1
 @SuppressLint("NewApi")
 public void download(VersionInfo version) {
   initDownload();
   AppLog.out(TAG, "更新地址:" + HttpUrl.OSS + version.getSourceUrl(), AppLog.LEVEL_INFO);
   DownloadManager.Request request =
       new DownloadManager.Request(Uri.parse(HttpUrl.OSS + version.getSourceUrl()));
   request.setDestinationInExternalPublicDir(DOWNLOAD_FOLDER_NAME, version.getVersionName());
   request.setTitle(version.getVersionName());
   request.setDescription(getString(R.string.app_name));
   request.setNotificationVisibility(DownloadManager.Request.VISIBILITY_VISIBLE_NOTIFY_COMPLETED);
   request.setVisibleInDownloadsUi(false);
   //        request.setMimeType(MMIMETYPE);
   downloadId = downloadManager.enqueue(request);
   /** save download id to preferences * */
   PreferencesUtils.putLong(getBaseContext(), KEY_NAME_DOWNLOAD_ID, downloadId);
   //        finish();
 }
Пример #2
0
 public void initDownload() {
   /**
    * get download id from preferences.<br>
    * if download id bigger than 0, means it has been downloaded, then query status and show right
    * text;
    */
   downloadManager = (DownloadManager) getSystemService(DOWNLOAD_SERVICE);
   downloadManagerPro = new DownloadManagerPro(downloadManager);
   downloadId = PreferencesUtils.getLong(getBaseContext(), KEY_NAME_DOWNLOAD_ID);
   completeReceiver = new CompleteReceiver();
   /** register download success broadcast * */
   registerReceiver(completeReceiver, new IntentFilter(DownloadManager.ACTION_DOWNLOAD_COMPLETE));
   initDownloaderDir();
 }