how to access getFilesDir() as an environment variable?
It's not possible.
Context.getFilesDir()
returns a path that is bound to your package and the Context
is required to access the package name.
Environment
is different as there's only constants that are common to all apps running on the same runtime.
However, a Context
is available practically everywhere in an Android application so this shouldn't really be a problem.
Follow up:
how about
Environment.getDataDirectory()
? how can I getdata\data
as fromdata\data\com.Myapp
using EnvironmentVar?
Environment.getDataDirectory()
just returns the part of the data directory common to all apps. For example, the /data/data
.
To get your own files dir (getFilesDir()
), your package name and "/files"
need to be appended to it. Context
implementation does this for you.
There is an excellent documentation on this done by a Githib user, which is really valuable. Maybe it will help someone:
https://gist.github.com/granoeste/5574148
Here is the entire contents posted from the documentation: