Android Download Manager Path Appears to be invalid sometimes
Asked Answered
B

2

6

Downloading through download Manager in android sometimes does not download and throw error path appears to be invalid and it corrects itself after sometime. This is very unusual behaviour of Android Download Manager .

I am downloading to external storage through request.setDestinationInExternalPublicDir("/app/" , my_app.apk)

And when it does not download it throw this error in logcat:-

W/DownloadManager: Path appears to be invalid: /storage/emulated/0/app/my_app.apk

I think its because i am downloading in custom directory in Android but i cannot use Environment.DIRECTORY_DOWNLOADS in this i have to download only in custom directory .

Please let me know if some one has an answer .)

Baseball answered 28/1, 2019 at 7:7 Comment(1)
did you find an answer I am facing the same thing?Seeger
O
0

First ensure that you have created a directory named "app" in which you want to store apks. To create a directory:

File path = Environment.getExternalStorageDirectory();  
            File dir = new File(path.getAbsolutePath(), "/app/");  
            if (!dir.exists()) {    
                 dir.mkdir();  
            }  

If you have already created such directory,then try this:

request.setDestinationInExternalPublicDir("/app/" , "my_app.apk");
Orabelle answered 5/5, 2020 at 18:1 Comment(0)
G
0

You must make ensure that the directory exist so you can use-

File root = new File(context.getExternalFilesDir(null).getAbsolutePath() + "/app/");
  if (!root.exists()) {
                root.mkdirs();
     }

Then you can use this to set the download manager path

request.setDestinationUri(Uri.parse("file://" + context.getExternalFilesDir(null).getAbsolutePath() + "/app/my_app.apk"));
Gimcrack answered 5/5, 2020 at 18:12 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.