Sanjana Nair Sanjana Nair - 1 year ago 106
Android Question

Storing data inside Android/data/pkgname

I am trying to add data into a folder which is inside Android/Data/packagename. So I am trying this out:

String tempsubdirtest = Environment.getExternalStorageDirectory()
+ File.separator + "/Android/data/" + getPackageName() + "/files/Images";

File subdirecttest = new File(tempsubdirtest);

if (!subdirecttest.exists())

The question is that is there an easy way to reduce the code for:

+ File.separator + "/Android/data/" + getPackageName()

instead of me typing /Android/data/ +getPackName etc.


Answer Source

You can use this existing method getExternalCacheDir

This will return the directory path plus a cache folder. So in your case, you can just exclude that cache path.


You might gonna check this, which will return something similar to what you want.

String pathImage = getExternalFilesDir(Environment.DIRECTORY_PICTURES).getPath();

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download