# Android quickstart

> The native Size guide button (Compose and Views), the shopper's recommended size, and the try-on window.

Source: https://docs.tryyoursize.com/quickstarts/android/

> **For your developer**
>
> **What it does:** Adds a native 'Size guide' button next to the size picker in our Android app. Connected shoppers see 'Your size: M'; a tap opens the TryYourSize window. The app receives sizes only.
>
> **Time needed:** About a day, including registering the app.
>
> **What to send them:** The test publishable key (pk_test_…) and our app's package name to register as android-app://<package>.

minSdk 24. Jetpack Compose and Views.

> **Caution: Test mode only for apps, for now**
>
> App origins (`android-app://…`) are accepted in test mode. Live mode for apps needs app verification (asset links), which is coming soon. Publication to our Maven repository is also coming soon: during the pilot we share the library with you.

## 1. Install

```kotlin
dependencies { implementation("com.tryyoursize:tryyoursize-android:0.1.0") }
```

## 2. Register your app

In Studio, add `android-app://<your package>` (lower case, for example `android-app://com.brand.shop`) to the allowed sites of your store for **test mode**.

## 3. Use it

The window needs an androidx `ComponentActivity` (for example `AppCompatActivity`).

```kotlin
val tys = TryYourSize(context, "pk_test_…")              // a secret key throws: keep sk_ on your server

// Compose, where your "Size guide" link was:
Row(verticalAlignment = Alignment.CenterVertically) {
    Text("Size"); Spacer(Modifier.weight(1f))
    SizeGuide(tys, "SKU-123", textStyle = MaterialTheme.typography.bodyMedium) { rec ->
        // On show and on every change. Preselect, but never over the shopper's own choice.
        if (rec.status == Recommendation.Status.READY && !touched) selected = rec.size
    }
}

// Views
val guide = SizeGuideView(context).apply { client = tys; product = "SKU-123"; variant = SizeGuideVariant.BUTTON }

// Without a button
val rec = tys.recommendation("SKU-123")                  // suspend; or getRecommendation("SKU-123") { result -> }
tys.present(activity, "SKU-123")
tys.on { e -> if (e is TryYourSize.Event.Size) select(e.selection.size) }
```

Call the SDK from the main thread.

**Button states:** "Size guide" → "Calculating your size…" → "Your size: **M**" (with the connected dot), or "Size guide · connected". Labels follow `locale` (en, es, fr, de, it).

**`Recommendation`:** `status` (`READY`, `COMPUTING`, `NO_SIZE`, `SIGNED_OUT`, `UNAVAILABLE`), `size` in your labels, `studioSize`, `wearableSizes`. It never starts a simulation.

## 4. Appearance

By default (`INHERIT`) the button and the window take your theme's text and background colours; the button takes the `textStyle` you pass.

```kotlin
val tys = TryYourSize(context, "pk_test_…", TryYourSize.Configuration(
    appearance = Appearance(colorPrimary = 0xFF3F51B5.toInt(), fontFamily = "Inter, Roboto", borderRadius = 12f,
        fonts = listOf("https://fonts.googleapis.com/css2?family=Inter:wght@400;600"))))
tys.appearance = tys.appearance.copy(colorPrimary = Color.BLACK)   // live: an open window restyles at once
```

## 5. Events and errors

- **Events:** `Ready`, `Open`, `Close`, `Size(SizeSelection)`, `LoadError(TryYourSizeException)`.
- **Error codes** (`TryYourSizeException.code`): `SECRET_KEY_IN_APP`, `INVALID_KEY`, `INVALID_APP_IDENTIFIER`, `INVALID_OPTION`, `WINDOW_UNREACHABLE`, `APP_NOT_ALLOWED`, `SIGN_IN_CANCELLED`, `SIGN_IN_UNAVAILABLE`.
- **Back** asks the window first: with unsaved measurements, the shopper confirms.

## Sign-in

Shoppers sign in inside the window (email and a 6-digit code), once per app. Sign-in through Custom Tabs with passkeys is coming soon.
