In my android app, I need to keep the settings for the api url, that varies based on the type of build (I will have one for debug/staging and release). Keeping this into the strings
file does not feel right since this folder has localized strings and there is nothing to localize about the api url.
What is the best place to keep this url in?
The best way in your case is store api url's in server because you can change them later. You'd create one url to fetch your api urls. Build your app based on an architecture like this. And don't forget anyone can see your server urls.
I found a solution to hide base url to keep api secured with NDK. Keep base64 encoded string inside cpp file and call that from java class and decode base64. Include c++ (NDK) support to your project. You can include this to your new or old project.
Android App Links are HTTP URLs that bring users directly to specific content in your Android app. Android App Links can drive more traffic to your app, help you discover which app content is used most, and make it easier for users to share and find content in an installed app.
The config file must be available at the "/sdcard/config. txt" of the android hardware.
You can use the BuildConfig
class, for example:
android {
buildTypes {
debug {
buildConfigField 'String', 'API_URL', 'http://...'
}
release {
buildConfigField 'String', 'API_URL', 'http://...'
}
}
}
Or, if you don't want to store the URL's in build.gradle
, you can use the debug
and release
folders to create a special class which stores the URL:
debug\src\java\com\myapp\ApiParam.java
release\src\java\com\myapp\ApiParam.java
Now, in your main
project, you can reference the ApiParam
class.
Resource file are fine for that, you don't have to put in in all the translation folders and what is nice about them is that you can override them from a library project to the main project.
If you don't want to use them, then a sample class with a constant string.
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