Android文件下载实现

Android文件下载实现代码如下:

通过:DownloadManager
Android文件下载实现_第1张图片

		//创建下载任务
        DownloadManager.Request request = new DownloadManager.Request(Uri.parse(url));
        //在通知栏中显示,默认就是显示的
        request.setNotificationVisibility(DownloadManager.Request.VISIBILITY_VISIBLE);
        request.setTitle("下载");
        request.setDescription("《用户协议》正在下载");
        request.setVisibleInDownloadsUi(true);
        //设置下载的路径
        File file = new File(mContext.getExternalFilesDir(Environment.DIRECTORY_DOWNLOADS), "合同.jpg");
        request.setDestinationUri(Uri.fromFile(file));
        file.getAbsolutePath();
        //获取DownloadManager
        DownloadManager downloadManager = (DownloadManager)mContext.getSystemService(DOWNLOAD_SERVICE);
        //将下载请求放入队列
        downloadManager.enqueue(request);

如果h5和Android混合开发下载文件,js文件下载实现如下

windows.location.href = ’下载文件链接‘    //注意,默认图片不会下载,只会预览,文件可下载

你可能感兴趣的:(个人日志,安卓)