Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to access getFilesDir() as an environment variable?

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).

like image 864
Elad Benda2 Avatar asked Jan 19 '14 12:01

Elad Benda2


People also ask

How to set environment variables using the Windows GUI?

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.

How to retrieve all environment variables along with their values?

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:

How do I access environment variables in PowerShell?

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:

How do I check the current environment variables?

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:


2 Answers

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 get data\data as from data\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.

like image 168
laalto Avatar answered Sep 22 '22 18:09

laalto


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:

enter image description here

enter image description here

like image 44
Manish Kumar Sharma Avatar answered Sep 19 '22 18:09

Manish Kumar Sharma