DISCLAIMER: This is a guideline sample application and is used for demonstrative and illustrative purposes only. This is not a production ready code.
This sample contains an Android project that you can use to learn more about the IBM Cloud App Configuration service.
- Log in to your IBM Cloud account.
- In the IBM Cloud catalog, search App Configuration and click App Configuration. The service provisioning page opens.
- Select a region - Currently, Dallas (us-south), London (eu-gb), Sydney (au-syd) and Washington DC (us-east) regions are supported.
- Select a pricing plan, resource group and configure your resource with a service name, or use the preset name.
- Click Create. A new service instance is created and the App Configuration dashboard is displayed.
- Download the source code
git clone https://github.com/IBM/appconfiguration-samples.git cd appconfiguration-samples/android-kotlin
- Install
jq
- command-line JSON processor.- You can install it from here
- Go to dashboard of your App Configuration instance in IBM Cloud UI.
- Navigate to Service Credentials section and generate a new set of credentials. Note down the
region
,guid
andapikey
. These credentials are required in the next steps. - From your terminal, execute the demo-android.sh script by running below command
$ cd appconfiguration-samples/common/script $ ./demo-android.sh
If any permission error occurred during script the execution, provide appropriate permission by running -
sudo chmod +x ./demo-android.sh
. And then execute the script. - Provide all the inputs during script execution. A sample example is shown in below figure
- Script execution takes time. Script is executed successfully only when you see the log
---Demo script complete---
at the end in your terminal. - This script will create the collections, feature flags, properties & segments using the default dev environment in the instance which are required for the sample android app
-
Import App Configuration client SDK Use either of the following options
- Download and import the package to your Android studio project
- Go to
File-->New-->Import Module
and provide the path of downloaded SDK - Then add
implementation project(path: ':lib')
in the module levelbuild.gradle
file dependencies.
- Go to
- Get the package through Gradle by adding the following
- Add below dependencies to module level
build.gradle
file
dependencies { implementation "com.ibm.cloud:appconfiguration-android-sdk:0.3.0" }
- Add below dependencies to module level
- Download and import the package to your Android studio project
-
Edit the android app
- In file
SplashActivity.kt
at line 39 & 40 provide theapikey
andguid
with the values you obtained from the Service credentials section of the instance. - And at line 45 provide the
region
parameter asAppConfiguration.REGION_EU_GB
for LondonAppConfiguration.REGION_US_SOUTH
for DallasAppConfiguration.REGION_AU_SYD
for SydneyAppConfiguration.REGION_US_EAST
for Washington DC
- Provide
collectionId
asblue-charge-android
&environmentId
(default value isdev
) at line 46.
- In file
-
Run the app
- On the homeactivity click on profile icon. Signup and create various users with different email ids.
- Additionally, register/create two users with email id alice@bluecharge.com & bob@bluecharge.com
- From the App Configuration service instance dashboard, navigate to Feature flags section.
- Turn ON the toggle for
Floating Profile
feature flag. Once turned ON, close & re-open the bluecharge android app. You would observe that user profile icon from the homeactivity toolbar is now displayed as a floating icon located bottom right of the homeactivity. And when the toggle is turned OFF the user profile icon is positioned back in the toolbar menu when the app is re-opened again. - Similarly, turn ON the toggle for 'Flight Booking' feature flag. Now re-open and login with either of alice@bluecharge.com or bob@bluecharge.com email id. Once logged in, you would see a Flight Booking button on homeactivity. If you try logging in with email ids other than alice & bob you'll not see the Flight Booking button, because alice & bob are a part of
Software testers
segment and the Flight Booking feature is enabled only forSoftware testers
segment. - Another use case is with numeric property called
Flight Booking Discount
. Navigate to Properties section on the App Configuration service instance dashboard to view this property. This property holds the discount value(of 5). - Re-open the app and navigate to flightactivity by clicking on Flight Booking button. You will see cardview discount coupon of 5% value. The discount will be 25% for user logging in with email id ending with
ibm.com
and it defaults to 5% for all other users, because users whose email is ending withibm.com
are part ofIBM employees segment
.
This project is released under the Apache 2.0 license. The license's full text can be found in LICENSE
See here for detailed docs on App Configuration service.