extendedplayerview

Android Client library for IBM Cloud App Configuration service

License

License

Categories

Categories

Configuration Application Layer Libs config
GroupId

GroupId

com.ibm.cloud
ArtifactId

ArtifactId

appconfiguration-android-sdk
Last Version

Last Version

2.0.0
Release Date

Release Date

Type

Type

aar
Description

Description

extendedplayerview
Android Client library for IBM Cloud App Configuration service
Project URL

Project URL

https://github.com/IBM/appconfiguration-android-client-sdk
Source Code Management

Source Code Management

https://github.com/IBM/appconfiguration-android-client-sdk

Download appconfiguration-android-sdk

How to add to project

<!-- https://jarcasting.com/artifacts/com.ibm.cloud/appconfiguration-android-sdk/ -->
<dependency>
    <groupId>com.ibm.cloud</groupId>
    <artifactId>appconfiguration-android-sdk</artifactId>
    <version>2.0.0</version>
    <type>aar</type>
</dependency>
// https://jarcasting.com/artifacts/com.ibm.cloud/appconfiguration-android-sdk/
implementation 'com.ibm.cloud:appconfiguration-android-sdk:2.0.0'
// https://jarcasting.com/artifacts/com.ibm.cloud/appconfiguration-android-sdk/
implementation ("com.ibm.cloud:appconfiguration-android-sdk:2.0.0")
'com.ibm.cloud:appconfiguration-android-sdk:aar:2.0.0'
<dependency org="com.ibm.cloud" name="appconfiguration-android-sdk" rev="2.0.0">
  <artifact name="appconfiguration-android-sdk" type="aar" />
</dependency>
@Grapes(
@Grab(group='com.ibm.cloud', module='appconfiguration-android-sdk', version='2.0.0')
)
libraryDependencies += "com.ibm.cloud" % "appconfiguration-android-sdk" % "2.0.0"
[com.ibm.cloud/appconfiguration-android-sdk "2.0.0"]

Dependencies

runtime (7)

Group / Artifact Type Version
org.jetbrains.kotlin : kotlin-stdlib jar 1.4.31
androidx.core » core-ktx jar 1.3.2
androidx.appcompat » appcompat jar 1.2.0
com.google.android.material » material jar 1.3.0
com.squareup.okhttp3 : okhttp jar 4.9.0
com.squareup.okhttp3 : okhttp-urlconnection jar 4.9.0
org.jetbrains.kotlinx : kotlinx-coroutines-core jar 1.4.3

Project Modules

There are no modules declared in this project.

IBM Cloud App Configuration Android client SDK

IBM Cloud App Configuration SDK is used to perform feature flag and property evaluation based on the configuration on IBM Cloud App Configuration service.

Overview

IBM Cloud App Configuration is a centralized feature management and configuration service on IBM Cloud for use with web and mobile applications, microservices, and distributed environments.

Instrument your applications with App Configuration Android SDK, and use the App Configuration dashboard, CLI or API to define feature flags or properties, organized into collections and targeted to segments. Toggle feature flag states in the cloud to activate or deactivate features in your application or environment, when required. You can also manage the properties for distributed applications centrally.

Contents

Prerequisites

Follow the below step

Kotlin

Installation Kotlin

Choose to integrate the AppConfiguration Android client SDK package using either of the following options:

  • Download and import the package to your Android Studio project
  • Get the package through Gradle

Initialize Kotlin SDK

  • Configure the Module level build.gradle and App level build.gradle files.

    1. Add IBM Cloud AppConfiguration Android client SDK dependency to Project level build.gradle file.

      repositories {
          mavenCentral()
      }
    2. Add IBM Cloud AppConfiguration Android client SDK dependency to Module level build.gradle file.

      dependencies {
          implementation "com.ibm.cloud:appconfiguration-android-sdk:2.0.0"
      }
  • Configure the AndroidManifest.xml file for Internet permission.

    	 <uses-permission android:name="android.permission.INTERNET"/>

Import Kotlin AppConfiguration SDK

initialization

  val appConfiguration = AppConfiguration.getInstance()

  appConfiguration.init( application,
                        AppConfiguration.REGION_US_SOUTH,
                        "guid",
                        "apikey")

  //To start the configuration fetching operation, set the collectionId and environmentId in the following way.
  appConfiguration.setContext("collectionId","environmentId")

  • region : Region name where the service instance is created. Use
    • AppConfiguration.REGION_US_SOUTH for Dallas
    • AppConfiguration.REGION_EU_GB for London
    • AppConfiguration.REGION_AU_SYD for Sydney
  • guid : GUID of the App Configuration service. Get it from the service instance credentials section of the dashboard
  • apikey : ApiKey of the App Configuration service. Get it from the service instance credentials section of the dashboard
  • collectionId : Id of the collection created in App Configuration service instance under the Collections section.
  • environmentId : Id of the environment created in App Configuration service instance under the Environments section.

Set listener for feature or property data changes

appConfiguration.registerConfigurationUpdateListener(object : ConfigurationUpdateListener {

    override fun onConfigurationUpdate() {
        // ADD YOUR CODE
    }
})

Get single feature

val feature: Feature? = appConfiguration.getFeature("featureId")

Get all features

val features: HashMap<String, Feature>? = appConfiguration.getFeatures();

Feature evaluation

val identityAttributes = JSONObject()
try {
    identityAttributes.put("city", "Bangalore")
    identityAttributes.put("country", "India")
} catch (e: JSONException) {
    e.printStackTrace()
}


val appConfiguration = AppConfiguration.getInstance()
val feature: Feature? = appConfiguration.getFeature("featureId")

if (feature?.getFeatureDataType() === Feature.FeatureType.NUMERIC) {

    val value = feature.getCurrentValue("identityId", identityAttributes)

} else if (feature?.getFeatureDataType() === Feature.FeatureType.BOOLEAN) {

    val value = feature.getCurrentValue("identityId", identityAttributes)

} else if (feature?.getFeatureDataType() === Feature.FeatureType.STRING) {

    val value = feature.getCurrentValue("identityId", identityAttributes)

}

Get single Property

val property: Property? = appConfiguration.getProperty("propertyId")

Get all Properties

val properties: HashMap<String, Property>? = appConfiguration.getProperties();

Property evaluation

JSONObject identityAttributes = new JSONObject();
try {
    identityAttributes.put("city", "Bangalore");
    identityAttributes.put("country", "India");
} catch (JSONException e) {
    e.printStackTrace();
}


val appConfiguration = AppConfiguration.getInstance()
val property: Property? = appConfiguration.getProperty("propertyId")
val value = property.getCurrentValue("identityId", identityAttributes)

Enable/Disable Logger (optional)

val appConfiguration = AppConfiguration.getInstance()

// Enable Logger 

appConfiguration.enableDebug(true)

// Disable Logger

appConfiguration.enableDebug(false)

Force fetch the configurations from server

appConfiguration.fetchConfigurations()

Java

Installation Java

Choose to integrate the AppConfiguration Android client SDK package using either of the following options:

  • Download and import the package to your Android Studio project
  • Get the package through Gradle

Initialize Java SDK

  • Configure the Module level build.gradle and App level build.gradle files.

    1. Add IBM Cloud AppConfiguration Android client SDK dependency to Project level build.gradle file.

      repositories {
          mavenCentral()
      }
    2. Add IBM Cloud AppConfiguration Android client SDK dependency to Module level build.gradle file.

      dependencies {
          implementation "com.ibm.cloud:appconfiguration-android-sdk:2.0.0"
      }
  • Configure the AndroidManifest.xml file for Internet permission.

    	 <uses-permission android:name="android.permission.INTERNET"/>

integrating Kotlin to Java project

  • Add the Kotlin gradle pluign to the Module level build.gradle

    dependencies {
            classpath "com.android.tools.build:gradle:4.1.1"
            classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
    }
  • Add kotlin-android plugin to the App level build.gradle

    plugins {
        id 'com.android.application'
        id 'kotlin-android'
    }

Import AppConfiguration Java SDK

      AppConfiguration appConfiguration = AppConfiguration.getInstance();
      appConfiguration.init(getApplication(), AppConfiguration.REGION_US_SOUTH, "guid", "apikey");

      // To start the configuration fetching operation, set the collectionId and environmentId in the following way.
      appConfiguration.setContext("collectionId", "environmentId");
  • region : Region name where the service instance is created. Use
    • AppConfiguration.REGION_US_SOUTH for Dallas
    • AppConfiguration.REGION_EU_GB for London
    • AppConfiguration.REGION_AU_SYD for Sydney
  • guid : GUID of the App Configuration service. Get it from the service instance credentials section of the dashboard
  • apikey : ApiKey of the App Configuration service. Get it from the service instance credentials section of the dashboard
  • collectionId : Id of the collection created in App Configuration service instance under the Collections section.
  • environmentId : Id of the environment created in App Configuration service instance under the Environments section.

Listen to the feature changes.

appConfiguration.registerConfigurationUpdateListener(new ConfigurationUpdateListener() {
    @Override
    public void onConfigurationUpdate() {
       // ADD YOUR CODE
    }
});

Get single feature

Feature feature = appConfiguration.getFeature("featureId");

Get all feature

HashMap<String,Feature> features =  appConfiguration.getFeatures();

Feature evaluation

JSONObject identityAttributes = new JSONObject();

try {
    identityAttributes.put("city", "Bengaluru");
    identityAttributes.put("country", "India");
} catch (JSONException e) {
    e.printStackTrace();
}

AppConfiguration appConfiguration = AppConfiguration.getInstance();
Feature feature = appConfiguration.getFeature("featureId")
if(feature != null) 
    switch (feature.getFeatureDataType())
        case STRING:
            String value = (String) feature.getCurrentValue(identityId, identityAttributes);
            System.out.println(value);
            break;
        case BOOLEAN:
            Boolean boolVal = (Boolean) feature.getCurrentValue(identityId, identityAttributes);
            System.out.println(boolVal);
            break;
        case NUMERIC:
            Integer intVal = (Integer) feature.getCurrentValue(identityId, identityAttributes);
            System.out.println(intVal);
            break;
    }
}

Get single Property

Property property = appConfiguration.getProperty("propertyId");

Get all Properties

HashMap<String,Property> properties =  appConfiguration.getProperties();

Property evaluation

JSONObject identityAttributes = new JSONObject();

try {
    identityAttributes.put("city", "Bengaluru");
    identityAttributes.put("country", "India");
} catch (JSONException e) {
    e.printStackTrace();
}


AppConfiguration appConfiguration = AppConfiguration.getInstance();
Property property = appConfiguration.getProperty("propertyId")
String value = (String) property.getCurrentValue(identityId, identityAttributes);

Enable/Disable Logger (optional)

AppConfiguration appConfiguration = AppConfiguration.getInstance();

// Enable Logger 
appConfiguration.enableDebug(true);


// Disable Logger

appConfiguration.enableDebug(false);

Force fetch the configurations from server

appConfiguration.fetchConfigurations()

License

This project is released under the Apache 2.0 license. The license's full text can be found in LICENSE

com.ibm.cloud

International Business Machines

Versions

Version
2.0.0
1.2.1
1.2.0
0.3.0
0.2.2
0.2.1
0.2.0
0.1.1
0.1.0
0.0.1