当前位置: 首页>>代码示例>>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;未经允许,请勿转载。