diff --git a/docs/docs/clients/client-side/android.md b/docs/docs/clients/client-side/android.mdx similarity index 72% rename from docs/docs/clients/client-side/android.md rename to docs/docs/clients/client-side/android.mdx index 7845d8787b00..bb8de94f4e24 100644 --- a/docs/docs/clients/client-side/android.md +++ b/docs/docs/clients/client-side/android.mdx @@ -5,7 +5,10 @@ description: Manage your Feature Flags and Remote Config in your Android applica slug: /clients/android --- -import CodeBlock from '@theme/CodeBlock'; import { AndroidVersion } from '@site/src/components/SdkVersions.js'; +import CodeBlock from '@theme/CodeBlock'; +import Tabs from '@theme/Tabs'; +import TabItem from '@theme/TabItem'; +import { AndroidVersion } from '@site/src/components/SdkVersions.js'; This SDK can be used for Android applications written in Kotlin. The source code for the client is available on [GitHub](https://github.com/Flagsmith/flagsmith-kotlin-android-client/). @@ -14,36 +17,49 @@ This SDK can be used for Android applications written in Kotlin. The source code ### Gradle -```groovy -repositories { +The Flagsmith Android SDK is available from [Maven Central](https://mvnrepository.com/artifact/com.flagsmith/flagsmith-kotlin-android-client). + + + + + +{`repositories { google() mavenCentral() } -``` -In your project path `app/build.gradle` add a new dependency: +dependencies { + implementation("com.flagsmith:flagsmith-kotlin-android-client:${AndroidVersion({})}") +}`} + + + -{`implementation("com.flagsmith:flagsmith-kotlin-android-client:`}"{`)`} + + + +{`repositories { + google() + mavenCentral() +} -## Basic Usage +dependencies { + implementation 'com.flagsmith:flagsmith-kotlin-android-client:${AndroidVersion({})}' +}`} + -The SDK is initialised against a single environment within a project on [https://flagsmith.com](https://flagsmith.com), -for example the Development or Production environment. You can find your Client-side Environment Key in the Environment -settings page. + + -## Initialization +## Initialisation -### Within your Activity inside `onCreate()` +Initialise the Flagsmith client in your Activity's `onCreate` method: ```kotlin lateinit var flagsmith : Flagsmith override fun onCreate(savedInstanceState: Bundle?) { - initFlagsmith(); -} - -private fun initFlagsmith() { - flagsmith = Flagsmith(environmentKey = FlagsmithConfigHelper.environmentDevelopmentKey, context = context) + flagsmith = Flagsmith(environmentKey = "your_client_side_environment_key", context = context) } ``` @@ -52,14 +68,14 @@ private fun initFlagsmith() { The Flagsmith SDK has various parameters for initialisation. Most of these are optional, and allow you to configure the Flagsmith SDK to your specific needs: -- `environmentKey` Take this API key from the Flagsmith dashboard and pass here -- `baseUrl` By default we'll connect to the Flagsmith backend, but if you self-host you can configure here +- `environmentKey` The client-side SDK key for your current Flagsmith environment. +- `baseUrl` If not using Flagsmith SaaS, set this to your Flagsmith API URL. For example `"https://flagsmith.example.com/api/v1/"` - `context` The current Context is required to use the Flagsmith Analytics functionality - `enableAnalytics` Enable analytics - default true. Disable this if you'd like to avoid the use of Context - `analyticsFlushPeriod` The period in seconds between attempts by the Flagsmith SDK to push analytic events to the server - `enableRealtimeUpdates` Enable the SDK to receive updates to features in real time while the app is running -- `defaultFlags` Provide default flags the the SDK to ensure values are availble when no network connection can be made +- `defaultFlags` Provide default flags to the SDK to ensure values are available when no network connection can be made - `cacheConfig` Disabled by default, but when enabled will allow Flagsmith to fall back to cached values when no network connection can be made - `request / read / writeTimeoutSeconds` Fine-grained control of the HTTP timeouts used inside the Flagsmith SDK @@ -167,34 +183,25 @@ the event that it cannot receive a response from our API. val defaultFlags = listOf( Flag( feature = Feature( - id = 345345L, name = "Flag 1", - createdDate = "2023‐07‐07T09:07:16Z", - description = "Flag 1 description", - type = "CONFIG", - defaultEnabled = true, - initialValue = "true" - ), enabled = true, featureStateValue = "value1" + ), + enabled = true, + featureStateValue = "value1", ), Flag( feature = Feature( - id = 34345L, name = "Flag 2", - createdDate = "2023‐07‐07T09:07:16Z", - description = "Flag 2 description", - type = "CONFIG", - defaultEnabled = true, - initialValue = "true" - ), enabled = true, featureStateValue = "value2" + ), + enabled = true, + featureStateValue = "value2", ), ) -// Then pass these during initialisation: flagsmith = Flagsmith( - environmentKey = FlagsmithConfigHelper environmentDevelopmentKey, + environmentKey = "your_client_side_environment_key", defaultFlags = defaultFlags, - context = context) - + context = context, +) ``` ### Cache @@ -206,8 +213,9 @@ initialisation: ```kotlin flagsmith = Flagsmith( environmentKey = FlagsmithConfigHelper environmentDevelopmentKey, - cacheConfig = FlagsmithCacheConfig(enableCache = true) - context = context) + cacheConfig = FlagsmithCacheConfig(enableCache = true), + context = context, +) ``` You can also set a TTL for the cache (in seconds) for finer control: @@ -226,9 +234,10 @@ By default, the client uses a default configuration. You can override the config realtime flag updates in your hosted environment you'll also need to pass the eventSourceUrl in a similar fashion: ```kotlin - flagsmith = Flagsmith( - environmentKey = Helper.environmentDevelopmentKey, - context = context, - baseUrl = "https://flagsmith.example.com/api/v1/"), - eventSourceUrl = "https://realtime.flagsmith.example.com/" +flagsmith = Flagsmith( + environmentKey = "your_client_side_environment_key", + context = context, + baseUrl = "https://flagsmith.example.com/api/v1/", + eventSourceUrl = "https://realtime.flagsmith.example.com/", +) ```