FolioReader / FolioReader-Android

A Java ePub reader and parser framework for Android.
BSD 3-Clause "New" or "Revised" License
2.24k stars 715 forks source link

How do I get path to /data/data folder android #385

Open benthemobileguy opened 5 years ago

benthemobileguy commented 5 years ago

I have some epub files that I saved to android internal storage. I have been using thislibrary to display this files but it keeps telling me the path destination is null.

So, I checked android studio's Device File Explorer and I found the files this location: /data/data/packageName/files/FileName

Am using this code to get path:

try{
            String path = getFilesDir().getPath() + "/" + fileName
            folioReader.openBook(path);
                Log.i("Path:", path);
        } catch (Exception e){
            e.printStackTrace();
        }
    }

It returns this path on my log cat:

/data/user/0/packageName/files/fileName

There seems to be a difference in the locations paths.

So, my question is this: how do I get path to this location?

/data/data/packageName/files/FileName
nphausg commented 5 years ago

Can you try this:

var path: String = context.getFilesDir().getAbsolutePath()

benthemobileguy commented 5 years ago

I finally resolved my issue. I discovered from my device file explorer that my files were saved as .txt instead of .epub extension. After converting them, it worked smoothly with this code:

var path: String = context.getFilesDir().getAbsolutePath()

Thanks for your effort!