I don't know if this is off-topic, but in Laravel, we can set variables in a .env
file, which we can then access using a getenv()
function to prevent from hard coding it in, which can be not secure.
Can we do the same in Android Studio (using Java)? As there is some information I rather not hard code.
Hope this makes sense.
I tried setting the variables in a class and accessing them through the class, but I feel there is a better way that is more similar to how it is done in Laravel.
Here's what I'm doing now but it's not what I'm looking for:
public class EnvVariables {
public final String API_KEY = "some API key";
public final String API_ENDPOINT = "https://example.com/api/v1/endpoint";
}
Then I used these variables wherever I needed them.
This does the job, BUT the class is still easily accessible, whereas a .env
is not (as it shouldn't be).