【发布时间】:2016-12-05 19:34:41
【问题描述】:
我有一个应用程序,其中包含一些指向网络上文件的链接。我希望在用户选择将文件下载到设备后 - 该文件将自动打开。 这是我的下载代码:
private void downloadFile(String url) {
if (GeneralHelper.isNetworkAvailable(this)) {
Uri uri = Uri.parse(url);
DownloadManager.Request r = new DownloadManager.Request(uri);
String fileName = url.substring( url.lastIndexOf('/')+ 1, url.length() );
// This put the download in the same Download dir the browser uses
r.setDestinationInExternalPublicDir(Environment.DIRECTORY_DOWNLOADS, fileName);
r.allowScanningByMediaScanner();
// Notify user when download is completed
// (Seems to be available since Honeycomb only)
r.setNotificationVisibility(DownloadManager.Request.VISIBILITY_VISIBLE_NOTIFY_COMPLETED);
// Start download
DownloadManager dm = (DownloadManager) getSystemService(DOWNLOAD_SERVICE);
dm.enqueue(r);
}
else {
// ....
}
}
下载完成后如何添加打开文件的代码?
【问题讨论】:
标签: android file android-download-manager