Get Application Directory

MByD picture MByD · Apr 3, 2011 · Viewed 187.1k times · Source

Does someone know how do I get the path of my application directory? (e.g. /data/data/my.app.lication/)

Currently I'm using this method: myActivity.getFilesDir().getParent(); but it seems to me like a workaround when there's a simpler solution. Also, the side-effect is the creation of the files directory, which is un-needed.

Clarification: First - Thanks for the repliers. I try to understand if there's already exists method that does it, not for another work-around.

Answer

James Wald picture James Wald · Oct 28, 2013

There is a simpler way to get the application data directory with min API 4+. From any Context (e.g. Activity, Application):

getApplicationInfo().dataDir

http://developer.android.com/reference/android/content/Context.html#getApplicationInfo()