Home > Software design >  Can I use direct file paths to access files stored in app specific storage?
Can I use direct file paths to access files stored in app specific storage?

Time:10-14

I have an app where I capture/download images and store them to the app specific storage using:

File fileToSave = new File(getApplicationContext().getExternalFilesDir(
                        Environment.DIRECTORY_PICTURES), "filename");

Then, I save the absolute path to the file in the db using:

saveToDb(fileToSave.getAbsolutePath())

My question is, will I be able to access the file later using this absolute path?

File file = new File(savedAbsolutePath);

Is this the best practice?

CodePudding user response:

will I be able to access the file later using this absolute path?

Yes, assuming the user did not delete it or something.

Is this the best practice?

If you want the user to have some ability to access the content independently of your app, using getExternalFilesDir() is a fine choice.

If you do not want the user to have independent access to the content, you could use getFilesDir() instead.

  • Related