3
我有一个应用程序,其中包含一些指向网络上文件的链接。我希望在用户选择将文件下载到设备后 - 文件将自动打开。 这是我下载的代码:在Android中下载后打开下载的文件
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 {
// ....
}
}
我如何添加代码来打开文件下载完成后?
http://blog.vogella.com/2011/06/14/android-downloadmanager -example/ 这很好。 – srijanshukla