0
 File oldFile = new File(dirPath+"/"+packageName+".apk");
        Log.e("Path ",oldFile.getPath());

my log returns this:

E/Path: /storage/emulated/0/Android/data/com.bazibaaz.app/files/com.YGD.GoldenBasket.apk

i have this file exactly on the path shown in the log, but this code:

oldFile.exists()

returns false!

i have permissions to read and write:

<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />

here is the picture of file (to prove its existence):

enter image description here

( path: internal storage/storage/emulated/0/Android/data/com.bazibaaz.app/files/com.YGD.GoldenBasket.apk)

Phantômaxx
  • 37,901
  • 21
  • 84
  • 115
Alireza Pir
  • 878
  • 1
  • 16
  • 41
  • Do you have runtime permissions too? – Vucko May 19 '19 at 10:42
  • @Vucko i grant this permission on my device in apps properties – Alireza Pir May 19 '19 at 10:42
  • Are you certain then that the file exists on that location? Printing a path merely isn't enough cause you can create a file with ANY path and `exists` method may return true or false still. – Vucko May 19 '19 at 10:44
  • @Vucko yes im seeing this file in this path right now :) – Alireza Pir May 19 '19 at 10:47
  • And the name of the file is actually the same? These dots and everything? – Vucko May 19 '19 at 10:56
  • @Vucko yes, and i updated the post with a picture of the file. – Alireza Pir May 19 '19 at 11:03
  • 1
    What's the permission/owner of that particular directory/file? Just guessing but is it possible that you're running a file manager with root permissions so you can see the file, but actually it's not accessible from other regular apps? – Frederick Zhang May 19 '19 at 11:07
  • That's odd. What is to the right of "files", there's another right arrow? Also, can you go into debug mode and list all files in `files` folder, to see if it shows this one? – Vucko May 19 '19 at 11:07
  • @Vucko yes that really is. yes there is right arrow, but there is no folder, its showing "files" folder content. i tried this: https://stackoverflow.com/questions/9530921/list-all-the-files-from-all-the-folder-in-a-single-list to list all files but it found nothing. – Alireza Pir May 19 '19 at 11:18
  • That must mean that your permissions are messed up. I had `listFiles` return nothing when some permission was missing or something. Maybe [this](https://stackoverflow.com/questions/26579869/how-can-i-let-users-access-the-internal-storage-directory-of-my-app) can help. Your file is on the internal storage rather than on the SD card. So maybe change to one of these folders to save it. – Vucko May 19 '19 at 12:10

0 Answers0