Android:使用DownloadManager类下载应用程序

b.i*_*b.i 2 android download

我正在尝试使用DownloadManager该类在Android中下载非市场应用程序.我正在做的是以下内容:

DownloadManager dm = (DownloadManager) getSystemService(DOWNLOAD_SERVICE);
Request request = new Request(Uri.parse("PATH_TO_MY_APP"));
long enqueue = dm.enqueue(request);
Run Code Online (Sandbox Code Playgroud)

通知栏显示我正在下载该应用程序.但我无法安装或在设备上找到它.我做错了什么?

小智 14

同样的问题.通过致电解决:

public DownloadManager.Request setDestinationUri (Uri uri)
Run Code Online (Sandbox Code Playgroud)

您需要具有WRITE_EXTERNAL_STORAGE权限.

Uri src_uri = Uri.parse("http://your.url.here/File.apk");
Uri dst_uri = Uri.parse("file:///mnt/sdcard/download/File.apk");

DownloadManager.Request req = new DownloadManager.Request(src_uri);
req.setDestinationUri(dst_uri);
DownloadManager dm = (DownloadManager) getSystemService(DOWNLOAD_SERVICE);
dm.enqueue(req);
Run Code Online (Sandbox Code Playgroud)