首页 > 系统 > Android > 正文

android DownloadManager

2019-11-08 00:27:37
字体:
来源:转载
供稿:网友
DownloadManager.Request request = new DownloadManager.Request(Uri.parse(url));request.setNotificationVisibility(DownloadManager.Request.VISIBILITY_VISIBLE_NOTIFY_COMPLETED);request.setVisibleInDownloadsUi(true);request.setTitle("下载");request.setDescription("正在更新管理软件");request.setDestinationInExternalFilesDir(context, Environment.DIRECTORY_DOWNLOADS, "upgrade.apk");DownloadManager downManager = (DownloadManager)context.getSystemService(Context.DOWNLOAD_SERVICE);long id= downManager.enqueue(request);SharedPReferences sPreferences = context.getSharedPreferences("download_id.info", Context.MODE_PRIVATE);sPreferences.edit().putLong("id", id).commit();

下载完成后,会产生一个广播消息。在Intent中,通过下载id来判断是哪个下载任务。

long downloadId = intent.getLongExtra(DownloadManager.EXTRA_DOWNLOAD_ID, -1);

Broadcast的Action如下

<intent-filter> <action android:name="android.intent.action.DOWNLOAD_COMPLETE" /></intent-filter>
上一篇:Android studio的安装

下一篇:Android备忘录

发表评论 共有条评论
用户名: 密码:
验证码: 匿名发表