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


Java DownloadManager.Request方法代碼示例

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


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

示例1: downloadAttachment

import android.app.DownloadManager; //導入方法依賴的package包/類
private void downloadAttachment(String url, String fileName) throws IOException {
        mDownloadManager =
                (DownloadManager) mContext.getSystemService(Context.DOWNLOAD_SERVICE);

        Uri urlToDownload = Uri.parse(url);

        List<String> pathSegments = urlToDownload.getPathSegments();
        DownloadManager.Request request = new DownloadManager.Request(urlToDownload);
        request.setTitle(fileName)
                .setDestinationInExternalPublicDir(Environment.DIRECTORY_DOWNLOADS,
                        pathSegments.get(pathSegments.size() - 1));

        mDownloadManager.enqueue(request);
//        enqueues.add(mDownloadManager.enqueue(request));

//        mContext.registerReceiver(mDownloadCompleteReceiver,
//                new IntentFilter(DownloadManager.ACTION_DOWNLOAD_COMPLETE));
    }
 
開發者ID:DSM-DMS,項目名稱:DMS,代碼行數:19,代碼來源:DownloadAttachmentTask.java

示例2: download

import android.app.DownloadManager; //導入方法依賴的package包/類
@Override
public DownloadTask download(String url, String filePath) {
    Uri uri = Uri.parse(url);
    DownloadManager.Request request = new DownloadManager.Request(uri);
    //設置允許使用的網絡類型,這裏是移動網絡和wifi都可以
    request.setAllowedNetworkTypes(DownloadManager.Request.NETWORK_WIFI);
    //禁止發出通知,既後台下載,如果要使用這一句必須聲明一個權限:
    // android.permission.DOWNLOAD_WITHOUT_NOTIFICATION
    //request.setShowRunningNotification(false);
    //不顯示下載界麵
    request.setVisibleInDownloadsUi(false);
    File dstFile = new File(filePath);
    request.setDestinationInExternalFilesDir(mContext , dstFile.getParent() , dstFile.getName());
    long id = mDownloadManager.enqueue(request);
    mDownloadList.add(id);
    DownloadTask task = new DownloadTask(id, url , filePath , 0 ,0 , System.currentTimeMillis());
    task.setDownloaderType(DownloaderFactory.TYPE_SYSTEM_DOWNLOAD);
    return task;
}
 
開發者ID:zhuangzaiku,項目名稱:AndroidCollection,代碼行數:20,代碼來源:SystemDownloader.java

示例3: startDownload

import android.app.DownloadManager; //導入方法依賴的package包/類
private void startDownload() {
    Snackbar.make(activity.findViewById(R.id.fragment_container), "Downloading started.", Snackbar.LENGTH_SHORT).show();

    String path = Environment.getExternalStorageDirectory().toString() + File.separator +
            Environment.DIRECTORY_DOWNLOADS + File.separator + "wulkanowy";

    File dir = new File(path);
    if(!dir.mkdirs()) {
        for (String aChildren : dir.list()) {
            new File(dir, aChildren).delete();
        }
    }

    DownloadManager.Request request = new DownloadManager.Request(Uri.parse(update.getUrlToDownload().toString()))
            .setAllowedNetworkTypes(DownloadManager.Request.NETWORK_WIFI | DownloadManager.Request.NETWORK_MOBILE)
            .setAllowedOverRoaming(false)
            .setTitle("Wulkanowy v" + update.getLatestVersionCode())
            .setDescription(update.getLatestVersion())
            .setVisibleInDownloadsUi(true)
            .setMimeType("application/vnd.android.package-archive")
            .setDestinationUri(Uri.fromFile(new File(path + File.separator + update.getLatestVersion() + ".apk")));

    downloadManager.enqueue(request);
}
 
開發者ID:wulkanowy,項目名稱:wulkanowy,代碼行數:25,代碼來源:Updater.java

示例4: startDownload

import android.app.DownloadManager; //導入方法依賴的package包/類
/**
 * 開始下載APK
 */
private void startDownload(String downUrl) {
    Log.i(TAG, "startDownload: ");
    //獲得係統下載器
    mManager = (DownloadManager) getSystemService(DOWNLOAD_SERVICE);
    //設置下載地址
    DownloadManager.Request request = new DownloadManager.Request(Uri.parse(downUrl));
    // 設置允許使用的網絡類型,這裏是移動網絡和wifi都可以
    request.setAllowedNetworkTypes(DownloadManager.Request.NETWORK_MOBILE | DownloadManager.Request.NETWORK_WIFI);
    request.setAllowedOverRoaming(false);
    //設置可以被掃描到
    request.allowScanningByMediaScanner();
    //設置下載文件的類型
    request.setMimeType("application/vnd.android.package-archive");
    // 顯示下載界麵
    request.setVisibleInDownloadsUi(true);
    //設置下載存放的文件夾和文件名字
    request.setDestinationInExternalPublicDir(Environment.DIRECTORY_DOWNLOADS, apkName);
    //設置下載時,通知欄是否顯示
    request.setNotificationVisibility(DownloadManager.Request.VISIBILITY_VISIBLE);
    //設置標題
    request.setTitle(apkName.split("_")[0]);
    //執行下載,並返回任務唯一id
    enqueue = mManager.enqueue(request);
}
 
開發者ID:Jusenr,項目名稱:AppFirCloud,代碼行數:28,代碼來源:DownLoadService.java

示例5: download

import android.app.DownloadManager; //導入方法依賴的package包/類
private static void download(Context context, String url, File saveDirectory, String fileName) {
    File file = new File(saveDirectory, fileName);

    XposedBridge.log("[SoundCloud Downloader] Download path: " + file.getPath());

    if (file.exists()) {
        Toast.makeText(context, "File already exists!", Toast.LENGTH_SHORT).show();
        return;
    }

    DownloadManager downloadManager = (DownloadManager) context.getSystemService(Context.DOWNLOAD_SERVICE);
    DownloadManager.Request request = new DownloadManager.Request(Uri.parse(url));
    request.setTitle(fileName);
    request.allowScanningByMediaScanner();
    request.setNotificationVisibility(DownloadManager.Request.VISIBILITY_VISIBLE_NOTIFY_COMPLETED);
    request.setDestinationUri(Uri.fromFile(file));

    try {
        downloadManager.enqueue(request);
        Toast.makeText(context, "Downloading...", Toast.LENGTH_SHORT).show();
    } catch (Exception e) {
        XposedBridge.log("[SoundCloud Downloader] Download Error: " + e.getMessage());
        Toast.makeText(context, "Download failed!", Toast.LENGTH_SHORT).show();
    }
}
 
開發者ID:skyguy126,項目名稱:Xposed-SoundCloudDownloader,代碼行數:26,代碼來源:XposedMod.java

示例6: startDownload

import android.app.DownloadManager; //導入方法依賴的package包/類
/**
 * 開始下載
 */
private void startDownload(String downUrl) {
    //獲得係統下載器
    dm = (DownloadManager) getSystemService(DOWNLOAD_SERVICE);
    //設置下載地址
    DownloadManager.Request request = new DownloadManager.Request(Uri.parse(downUrl));
    //設置下載文件的類型
    request.setMimeType("application/vnd.android.package-archive");
    //設置下載存放的文件夾和文件名字
    request.setDestinationInExternalPublicDir(Environment.DIRECTORY_DOWNLOADS, apkname);
    //設置下載時或者下載完成時,通知欄是否顯示
    request.setNotificationVisibility(DownloadManager.Request.VISIBILITY_VISIBLE_NOTIFY_COMPLETED);
    request.setTitle("下載新版本");
    //執行下載,並返回任務唯一id
    enqueue = dm.enqueue(request);
}
 
開發者ID:tututututututu,項目名稱:BaseCore,代碼行數:19,代碼來源:DownloadService.java

示例7: downloadvideo

import android.app.DownloadManager; //導入方法依賴的package包/類
public void downloadvideo(String pathvideo)
{
    if(pathvideo.contains(".mp4"))
    {
        File directory = new File(Environment.getExternalStorageDirectory()+File.separator+"Facebook Videos");
        directory.mkdirs();
        DownloadManager.Request request = new DownloadManager.Request(Uri.parse(pathvideo));
        int Number=pref.getFileName();
        request.allowScanningByMediaScanner();
        request.setAllowedNetworkTypes(DownloadManager.Request.NETWORK_WIFI | DownloadManager.Request.NETWORK_MOBILE);
        request.setNotificationVisibility(DownloadManager.Request.VISIBILITY_VISIBLE_NOTIFY_COMPLETED);
        File root = new File(Environment.getExternalStorageDirectory() + File.separator+"Facebook Videos");
        Uri path = Uri.withAppendedPath(Uri.fromFile(root), "Video-"+Number+".mp4");
        request.setDestinationUri(path);
        DownloadManager dm = (DownloadManager)getActivity().getSystemService(getActivity().DOWNLOAD_SERVICE);
        if(downloadlist.contains(pathvideo))
        {
            Toast.makeText(getActivity().getApplicationContext(),"The Video is Already Downloading",Toast.LENGTH_LONG).show();
        }
        else
        {
            downloadlist.add(pathvideo);
            dm.enqueue(request);
            Toast.makeText(getActivity().getApplicationContext(),"Downloading Video-"+Number+".mp4",Toast.LENGTH_LONG).show();
            Number++;
            pref.setFileName(Number);
        }

    }
}
 
開發者ID:adarshgumashta,項目名稱:Facebook-Video-Downloader,代碼行數:31,代碼來源:HomeFragment.java

示例8: downloadWithSystemManager

import android.app.DownloadManager; //導入方法依賴的package包/類
@ProtoMethod(description = "Downloads a file from a given Uri. Returns the progress", example = "")
public void downloadWithSystemManager(String url, final ReturnInterface callback) {
    final DownloadManager dm = (DownloadManager) getContext().getSystemService(getContext().DOWNLOAD_SERVICE);
    DownloadManager.Request request = new DownloadManager.Request(Uri.parse(url));
    final long enqueue = dm.enqueue(request);

    BroadcastReceiver receiver = new BroadcastReceiver() {
        @Override
        public void onReceive(Context context, Intent intent) {
            String action = intent.getAction();
            if (DownloadManager.ACTION_DOWNLOAD_COMPLETE.equals(action)) {
                long downloadId = intent.getLongExtra(DownloadManager.EXTRA_DOWNLOAD_ID, 0);
                DownloadManager.Query query = new DownloadManager.Query();
                query.setFilterById(enqueue);
                Cursor c = dm.query(query);
                if (c.moveToFirst()) {
                    int columnIndex = c
                            .getColumnIndex(DownloadManager.COLUMN_STATUS);
                    if (DownloadManager.STATUS_SUCCESSFUL == c.getInt(columnIndex)) {
                        if (callback != null) callback.event(null);
                        // callback successful
                    }
                }
            }
        }
    };

    getContext().registerReceiver(receiver, new IntentFilter(DownloadManager.ACTION_DOWNLOAD_COMPLETE));


}
 
開發者ID:victordiaz,項目名稱:phonk,代碼行數:32,代碼來源:PNetwork.java

示例9: FetchUrlMimeType

import android.app.DownloadManager; //導入方法依賴的package包/類
public FetchUrlMimeType(Context context, DownloadManager.Request request, String uri,
		String cookies, String userAgent) {
	mContext = context.getApplicationContext();
	mRequest = request;
	mUri = uri;
	mCookies = cookies;
	mUserAgent = userAgent;
	Toast.makeText(mContext, R.string.download_pending, Toast.LENGTH_SHORT).show();
}
 
開發者ID:Louis19910615,項目名稱:youkes_browser,代碼行數:10,代碼來源:FetchUrlMimeType.java

示例10: downLoadApk

import android.app.DownloadManager; //導入方法依賴的package包/類
private void downLoadApk(FirAppInfo appInfo) {
    downloadManager = (DownloadManager) activity.getSystemService(Context.DOWNLOAD_SERVICE);
    DownloadManager.Request request = new DownloadManager.Request(Uri.parse(appInfo.getAppDirectInstallUrl()));
    request.setDestinationInExternalFilesDir(activity, Environment.DIRECTORY_DOWNLOADS, "update.apk");
    request.setTitle(appInfo.getAppName());
    request.setDescription(appInfo.getAppVersionShort());
    request.setNotificationVisibility(DownloadManager.Request.VISIBILITY_VISIBLE_NOTIFY_COMPLETED);
    request.setVisibleInDownloadsUi(false);
    request.setMimeType("application/cn.trinea.download.file");
    downloadId = downloadManager.enqueue(request);
}
 
開發者ID:shenhuanet,項目名稱:AndroidOpen,代碼行數:12,代碼來源:FirUpdater.java

示例11: initDownload

import android.app.DownloadManager; //導入方法依賴的package包/類
private void initDownload(String downloadUrl) {
    downloadManager = (DownloadManager) mContext.getSystemService(Context.DOWNLOAD_SERVICE);
    Uri uri = Uri.parse(downloadUrl);//"http://app.mi.com/download/25323"
    downloadRequest = new DownloadManager.Request(uri);
    // 設置目標存儲在外部目錄,一般位置可以用
    downloadRequest.setDestinationInExternalFilesDir(mContext, Environment.DIRECTORY_DOWNLOADS, downloadFileName);
    //下載的文件能被其他應用掃描到
    downloadRequest.allowScanningByMediaScanner();
    //設置被係統的Downloads應用掃描到並管理,默認true
    downloadRequest.setVisibleInDownloadsUi(true);
    //限定在WiFi還是手機網絡(NETWORK_MOBILE)下進行下載
    downloadRequest.setAllowedNetworkTypes(DownloadManager.Request.NETWORK_WIFI);
    // 設置mime類型,這裏看服務器配置,一般國家化的都為utf-8編碼。
    downloadRequest.setMimeType("application/vnd.android.package-archive");
    /**
     * 設置notification顯示狀態
     * Request.VISIBILITY_VISIBLE:在下載進行的過程中,通知欄中會一直顯示該下載的Notification,當下載完成時,該Notification會被移除,這是默認的參數值。
     * Request.VISIBILITY_VISIBLE_NOTIFY_COMPLETED:在下載過程中通知欄會一直顯示該下載的Notification,在下載完成後該Notification會繼續顯示,直到用戶點擊該
     * Notification或者消除該Notification。
     * Request.VISIBILITY_VISIBLE_NOTIFY_ONLY_COMPLETION:隻有在下載完成後該Notification才會被顯示。
     * Request.VISIBILITY_HIDDEN:不顯示該下載請求的Notification。如果要使用這個參數,需要在應用的清單文件中加上android.permission.DOWNLOAD_WITHOUT_NOTIFICATION
     */
    downloadRequest.setNotificationVisibility(DownloadManager.Request.VISIBILITY_HIDDEN);
    //設置notification的標題
    downloadRequest.setTitle("");
    //設置notification的描述
    downloadRequest.setDescription("");
}
 
開發者ID:mangestudio,項目名稱:GCSApp,代碼行數:29,代碼來源:DownloadUtil.java

示例12: download

import android.app.DownloadManager; //導入方法依賴的package包/類
public static List<Long> download(FontInfo font, List<String> files, Context context, boolean allowDownloadOverMetered) {
    DownloadManager downloadManager = (DownloadManager) context.getSystemService(Context.DOWNLOAD_SERVICE);
    if (downloadManager == null) {
        return null;
    }

    Cursor cursor = downloadManager.query(new DownloadManager.Query()
            .setFilterByStatus(DownloadManager.STATUS_PAUSED
                    | DownloadManager.STATUS_PENDING
                    | DownloadManager.STATUS_RUNNING));

    if (cursor != null) {
        if (cursor.getCount() > 0) {
            cursor.moveToFirst();

            do {
                int titleIndex = cursor.getColumnIndex(DownloadManager.COLUMN_TITLE);
                String file = cursor.getString(titleIndex);
                Log.d(TAG, file + " is already downloading");
                files.remove(file);
            } while (cursor.moveToNext());
        }

        cursor.close();
    }

    List<Long> ids = new ArrayList<>();
    for (String f : files) {
        DownloadManager.Request request = new DownloadManager.Request(Uri.parse(font.getUrlPrefix() + f))
                .setTitle(f)
                .setDestinationInExternalFilesDir(context, null, f)
                .setVisibleInDownloadsUi(false)
                .setAllowedOverMetered(allowDownloadOverMetered)
                .setNotificationVisibility(DownloadManager.Request.VISIBILITY_VISIBLE);
        ids.add(downloadManager.enqueue(request));
    }

    return ids;
}
 
開發者ID:RikkaApps,項目名稱:FontProvider,代碼行數:40,代碼來源:FontManager.java

示例13: queueDownload

import android.app.DownloadManager; //導入方法依賴的package包/類
@ReactMethod
public void queueDownload(String url, ReadableMap headers, ReadableMap config, Callback onStart) {
    try {
        DownloadManager.Request request = downloader.createRequest(url, headers, config);
        long downloadId = downloader.queueDownload(request);
        onStart.invoke(null, String.valueOf(downloadId));
    } catch (Exception e) {
        onStart.invoke(e.getMessage(), null);
    }
}
 
開發者ID:master-atul,項目名稱:react-native-simple-download-manager,代碼行數:11,代碼來源:ReactNativeDownloadManagerModule.java

示例14: downloadImage

import android.app.DownloadManager; //導入方法依賴的package包/類
private void downloadImage(String url, PhotoFragment.ActionType actionType) {
    if (null == getActivity()) return;
    String filename = mPhotos.id + "_" + mPhotos.user.name + PixelsApplication.DOWNLOAD_PHOTO_FORMAT;
    mDownloadManager = (DownloadManager) getActivity().getSystemService(Context.DOWNLOAD_SERVICE);
    DownloadManager.Request request = new DownloadManager.Request(Uri.parse(url))
            .setTitle(filename)
            .setDestinationInExternalPublicDir(PixelsApplication.DOWNLOAD_PATH, filename)
            .setVisibleInDownloadsUi(false)
            .setNotificationVisibility(actionType == PhotoFragment.ActionType.DOWNLOAD ? DownloadManager.Request.VISIBILITY_VISIBLE_NOTIFY_COMPLETED : DownloadManager.Request.VISIBILITY_VISIBLE);

    request.allowScanningByMediaScanner();
    downloadReference = mDownloadManager.enqueue(request);
}
 
開發者ID:alphater,項目名稱:garras,代碼行數:14,代碼來源:PhotoFragment.java

示例15: startUpdateDownload

import android.app.DownloadManager; //導入方法依賴的package包/類
/**
 * Handles downloading of new version of AniTrend
 * </br>
 *
 * @param url url of the actual file not a redirect urls
 * @param name file name to set when download is completed
 */
public long startUpdateDownload(String url, String name) {
    DownloadManager.Request request = new DownloadManager.Request(Uri.parse(url));
    request.setTitle(name);
    request.allowScanningByMediaScanner();
    String ext = MimeTypeMap.getFileExtensionFromUrl(url);
    request.setMimeType(mimeType.getMimeTypeFromExtension(ext));
    request.setDescription(context.getString(R.string.text_downloading_update));
    request.setDestinationInExternalPublicDir(Environment.DIRECTORY_DOWNLOADS, name);
    request.setNotificationVisibility(DownloadManager.Request.VISIBILITY_VISIBLE_NOTIFY_COMPLETED);
    return manager.enqueue(request);
}
 
開發者ID:wax911,項目名稱:anitrend-app,代碼行數:19,代碼來源:DownloaderService.java


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