當前位置: 首頁>>代碼示例>>Java>>正文


Java DownloadManager.addCompletedDownload方法代碼示例

本文整理匯總了Java中android.app.DownloadManager.addCompletedDownload方法的典型用法代碼示例。如果您正苦於以下問題:Java DownloadManager.addCompletedDownload方法的具體用法?Java DownloadManager.addCompletedDownload怎麽用?Java DownloadManager.addCompletedDownload使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在android.app.DownloadManager的用法示例。


在下文中一共展示了DownloadManager.addCompletedDownload方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: onPostExecute

import android.app.DownloadManager; //導入方法依賴的package包/類
@Override
protected void onPostExecute(Boolean success) {
    DownloadManager manager =
            (DownloadManager) mContext.getSystemService(Context.DOWNLOAD_SERVICE);
    if (success) {
        String path = mDownloadInfo.getFilePath();
        if (!TextUtils.isEmpty(path)) {
            // Move the downloaded content from the app directory to public directory.
            File fromFile = new File(path);
            String fileName = fromFile.getName();
            File toFile = new File(Environment.getExternalStoragePublicDirectory(
                    Environment.DIRECTORY_DOWNLOADS), fileName);
            if (fromFile.renameTo(toFile)) {
                manager.addCompletedDownload(
                        fileName, mDownloadInfo.getDescription(), false,
                        mDownloadInfo.getMimeType(), toFile.getPath(),
                        mDownloadInfo.getContentLength(), true);
            } else if (fromFile.delete()) {
                Log.w(TAG, "Failed to rename the file.");
                return;
            } else {
                Log.w(TAG, "Failed to rename and delete the file.");
            }
        }
        showNextUrlDialog(mOMAInfo);
    } else if (mDownloadId != DownloadItem.INVALID_DOWNLOAD_ID) {
        // Remove the downloaded content.
        manager.remove(mDownloadId);
    }
}
 
開發者ID:rkshuai,項目名稱:chromium-for-android-56-debug-video,代碼行數:31,代碼來源:OMADownloadHandler.java

示例2: onDownloadTaskFile

import android.app.DownloadManager; //導入方法依賴的package包/類
@Override
        public void onDownloadTaskFile(boolean success, int id, String data) {
            if (success) {
                byte[] inData = Base64.decode(data, Base64.DEFAULT);
                for (KanboardTaskFile f: files) {
                    if (f.getId() == id) {
                        try {
                            File file = new File(Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DOWNLOADS), f.getName());
                            FileOutputStream outData = new FileOutputStream(file);
                            outData.write(inData);
                            outData.close();
                            String mime = MimeTypeMap.getSingleton().getMimeTypeFromExtension(MimeTypeMap.getFileExtensionFromUrl(Uri.fromFile(file).toString()));
                            if (mime == null) {
                                mime = "application/octet-stream";
                            }
                            if (BuildConfig.DEBUG) {
                                Log.d(Constants.TAG, Uri.fromFile(file).toString());
                                Log.d(Constants.TAG, mime);
                            }
                            DownloadManager dm = (DownloadManager) getSystemService(Context.DOWNLOAD_SERVICE);
                            dm.addCompletedDownload(file.getName(), "Kandroid download", false, mime, file.getPath(), file.length(), true);
//                            Snackbar.make(findViewById(R.id.root_layout), String.format(Locale.getDefault(), "Saved file to: %s", file.getPath()), Snackbar.LENGTH_LONG).show();
                        } catch (IOException e) {
                            Log.w(Constants.TAG, "IOError writing file");
                            e.printStackTrace();
                        }
                        break;
                    }
                }
            } else {
                Snackbar.make(findViewById(R.id.root_layout), "Unable to download file", Snackbar.LENGTH_LONG).show();
            }
        }
 
開發者ID:andresth,項目名稱:Kandroid,代碼行數:34,代碼來源:TaskDetailActivity.java


注:本文中的android.app.DownloadManager.addCompletedDownload方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。