2

I am trying to download a non-market application in Android using the DownloadManager class. what I am doing is the following:

DownloadManager dm = (DownloadManager) getSystemService(DOWNLOAD_SERVICE);
Request request = new Request(Uri.parse("PATH_TO_MY_APP"));
long enqueue = dm.enqueue(request);

The notification bar shows me that the app is being downloaded. But I am not able to install it or to find it on the device. What I am doing wrong?

b.i
  • 1,087
  • 4
  • 22
  • 43
  • what does it do when you try to install it? If you type in your path to the stock browser is it able to download and install your application? – FoamyGuy Jun 20 '12 at 13:56
  • yes, the app is downloaded and installed when i try to install it from the browser. – b.i Jun 20 '12 at 14:03
  • and what does it do when you try to install the one that comes from your code? Any specific error? – FoamyGuy Jun 20 '12 at 14:05
  • No errors. I can access my apk from the Downloads and when I clik on it, it says: Parse error. There is a problem parsing the package. – b.i Jun 20 '12 at 14:10
  • that is a definite sign that your apk file is corrupted somehow. Not sure why though. it seems to be somewhat difficult to google for DownloadManager API stuff because of the plethora of "Download Manager" applications that are available, they flood the results. =( – FoamyGuy Jun 20 '12 at 14:32
  • can you check whether download successfully happened or not through code like Cursor c = downloadManager.query(new DownloadManager.Query().setFilterById(dwnId)); – Ganesh K Jun 20 '12 at 14:34
  • @vrs: by writing: String uriString = c.getString(c.getColumnIndex(DownloadManager.COLUMN_LOCAL_URI)); I get: content://downloads/my_downloads/196. How can i change the path for downloads? – b.i Jun 20 '12 at 14:46
  • 1
    @b.i you better read android docs and do practice common ware download manager demo example in below link. http://developer.android.com/reference/android/app/DownloadManager.Request.html#setDestinationUri%28android.net.Uri%29 – Ganesh K Jun 20 '12 at 14:55
  • http://stackoverflow.com/questions/5877753/android-how-to-use-download-manager-class – Ganesh K Jun 20 '12 at 14:56

1 Answers1

15

Same problem. Solved with a call to:

public DownloadManager.Request setDestinationUri (Uri uri)

You need to have WRITE_EXTERNAL_STORAGE permission.

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);
Robert
  • 166
  • 1
  • 2