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.
Directory of windows forms application (.exe) It contains path of the .exe file (that started the application) including the executable file name. To get only the folder part of the path, use static method GetDirectoryName of Path class.
To do this you can use Directory class: Directory. GetCurrentDirectory();
StartupPath property returns the path for the executable file that started the application, not the path where the application executable is stored. ExecutablePath property returns the path for the executable file that started the application, including the executable name.
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()
PackageManager m = getPackageManager(); String s = getPackageName(); PackageInfo p = m.getPackageInfo(s, 0); s = p.applicationInfo.dataDir;
If eclipse worries about an uncaught NameNotFoundException
, you can use:
PackageManager m = getPackageManager(); String s = getPackageName(); try { PackageInfo p = m.getPackageInfo(s, 0); s = p.applicationInfo.dataDir; } catch (PackageManager.NameNotFoundException e) { Log.w("yourtag", "Error Package name not found ", e); }
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With