I want to access getFilesDir()
which is a context method.
Is there any way to access it similarly to the way I access external-storage?
Environment.getExternalStorageDirectory();
meaning as an environment variable?
Maybe application static context? as I want to call this from a non-context class (same app service, but not an activity).
Follow the steps to set environment variables using the Windows GUI: 1. Press Windows + R to open the Windows Run prompt. 2. Type in sysdm.cpl and click OK. 3. Open the Advanced tab and click on the Environment Variables button in the System Properties window. 4. The Environment Variables window is divided into two sections.
To retrieve all environment variables along with their values, call the GetEnvironmentVariables method. Environment variable names are case-sensitive on Linux and macOS but are not case-sensitive on Windows. On Windows systems, the environment block of the current process includes:
The PowerShell Environment provider lets you access environment variables in a PowerShell drive (the Env: drive). This drive looks much like a file system drive. To go to the Env: drive, type: PowerShell. Set-Location Env:
The method for checking current environment variables depends on whether you are using the Command Prompt or Windows PowerShell: In the Command Prompt, use the following command to list all environment variables: If you are using Windows PowerShell, list all the environment variables with:
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:
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