Last active
July 2, 2024 08:28
-
-
Save dhiegoabrantes/c32b654560739f3de65972c032085b2f to your computer and use it in GitHub Desktop.
API Key on BuildConfig
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| apply plugin: 'com.android.application' | |
| android { | |
| compileSdkVersion 23 | |
| buildToolsVersion "25.0.2" | |
| defaultConfig { | |
| applicationId "com.udacity.learn.android" | |
| minSdkVersion 21 | |
| targetSdkVersion 23 | |
| versionCode 1 | |
| versionName "1.0" | |
| testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner" | |
| //Here, we are declaring our API Key! | |
| buildConfigField 'String', 'MY_API_KEY', "\"my_api_key_content\"" | |
| } | |
| buildTypes { | |
| release { | |
| minifyEnabled false | |
| proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' | |
| } | |
| } | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import android.support.v7.app.AppCompatActivity; | |
| import android.os.Bundle; | |
| import android.widget.Toast; | |
| import com.udacity.learn.android.BuildConfig; | |
| import com.udacity.learn.android.R; | |
| public class MainActivity extends AppCompatActivity { | |
| @Override | |
| protected void onCreate(Bundle savedInstanceState) { | |
| super.onCreate(savedInstanceState); | |
| setContentView(R.layout.activity_main); | |
| //at this point, we are using the api key that we have defined in the build config! | |
| Toast.makeText(this, BuildConfig.MY_API_KEY, Toast.LENGTH_LONG).show(); | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment