> For the complete documentation index, see [llms.txt](https://docs.multiset.ai/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.multiset.ai/native-sdk/android-native/api-reference/map-scanning.md).

# Map Scanning (Non-LiDAR)

Record a new VPS map on an Android device without LiDAR: the MultiSetMappingSource boundary, the scan lifecycle, drafts and uploads.

## Overview

From version 2.1.0 the Android SDK can record a new map. A scan keeps camera frames, plus depth when the device has it, packages them as `MappingData.zip`, saves the package as a draft and uploads it to your account with the SDK's own credentials. No LiDAR sensor is needed. The API has the same shape as the iOS SDK's.

The scan engine lives in the SDK, behind `MultiSetSDK.mapping` (a `MultiSetMapping`). As with localization, your AR runtime supplies the camera through an interface, `MultiSetMappingSource`. The sample app's ARCore implementation is `mapping/ArMappingSource`.

{% hint style="info" %}
`MultiSetSDK.mapping` needs `MultiSetSDK.initialize()` to have run, because scans are stored in the app's no-backup files directory. Before that it throws `IllegalStateException`. Scanning makes no network request, so it does not wait for authentication; uploading does. `release()` drops the instance, deletes a scan that was not saved, and stops uploads in progress.
{% endhint %}

The package follows the [mobile map upload](https://docs.multiset.ai/fundamentals/rest-api-docs/map-upload/mobile-map-upload.md) format, so a scan uploaded from the SDK is processed like any other mobile capture.

***

## The host side

```kotlin
interface MultiSetMappingSource {
    val depthSupported: Boolean                                  // the AR session runs a depth API
    val locationProvider: MappingLocationProvider? get() = null  // geo-tags the map; 0, 0, 0 without it
    fun startPreview()                                           // camera running, coverage display still
    fun startRecording()                                         // clear the coverage display and accumulate
    fun pause()                                                  // the SDK has stopped using the source
    suspend fun acquireRGBFrame(): MappingRGBFrame?              // the latest frame's pose; null while not tracking
}

interface MappingRGBFrame {
    val position: Vec3                                           // raw AR camera pose
    val rotation: Quat
    val timestamp: Double                                        // AR frame clock in seconds, monotonic
    val hasDepth: Boolean                                        // a depth image exists for this frame
    fun readImage(): MappingCameraImage?                         // that same frame's pixels; null skips it
}
```

Your app also reports to the facade, from the AR scene update and the activity lifecycle:

```kotlin
mapping.reportTrackingSample(MappingTrackingSample(trackingState, position, timestamp, featurePointCount, pixelIntensity))
mapping.reportSourceInterrupted()      // from onPause, before super.onPause()
mapping.reportSourceFailure(message)   // the AR session failed
```

**Pose first, pixels later, same frame.** `acquireRGBFrame()` returns only the pose. The SDK calls `readImage()` only for a frame that passes every check: tracking has settled, the camera has moved at least 5 cm or turned at least 5°, and depth is present when the scan needs it. That call comes on the same main-thread turn, straight after `acquireRGBFrame()`, and must return the pixels of *that* frame. If the runtime has moved on, return `null` and the frame is skipped. Build the image with `MappingCameraImage.copyOf(cameraImage, intrinsics, depthImage)`, which copies a `YUV_420_888` image and an optional `DEPTH16` image; you close both. Pass the raw pose and the camera image's own intrinsics. The SDK crops to 4:3, scales to 960 × 720 and converts the pose itself.

**Tracking samples drive the scan.** Report one `MappingTrackingSample` per AR camera update, with the runtime's `MappingTrackingState` (`NORMAL`, `INITIALIZING`, `RELOCALIZING`, `EXCESSIVE_MOTION`, `INSUFFICIENT_FEATURES` or `UNAVAILABLE`), the raw camera position, the frame time on the same clock as `MappingRGBFrame.timestamp`, the visible feature-point count and, if you have it, the ambient light intensity from 0 to 1. Frames are taken only while the latest sample is `NORMAL`, and a tracking loss or a pose jump deletes the frames from the second before it.

**Depth is all or none.** When `depthSupported` is `true`, the scan waits up to 2 s from the start of recording for a frame with depth. If one arrives, every frame the scan keeps carries depth. If none arrives in time, the whole scan is RGB only.

***

## Running a scan

```kotlin
val mapping = MultiSetSDK.mapping
mapping.setSource(arMappingSource)
lifecycleScope.launch { repeatOnLifecycle(Lifecycle.State.STARTED) { mapping.scan.collect { render(it) } } }

recordButton.setOnClickListener { mapping.startScan() }
stopButton.setOnClickListener {
    lifecycleScope.launch {
        when (mapping.stopScan()) {
            MappingStopOutcome.PACKAGED -> showNameCard()
            MappingStopOutcome.DISCARDED_TOO_SHORT -> showTooShort()
            MappingStopOutcome.FAILED, MappingStopOutcome.NOT_RECORDING -> Unit   // scan.phase says why
        }
    }
}

override fun onResume() { super.onResume(); mapping.beginPreview() }
override fun onPause() { mapping.reportSourceInterrupted(); super.onPause() }
```

Call `MultiSetMapping` from the main thread. `MultiSetMapping` outlives the activity, so in `onDestroy` call `endPreview()` and `setSource(null)` only while the attached source is still your screen's own: a newer screen may have attached its source already.

`scan` is a `StateFlow<MappingScanState>`:

| Phase             | What happens                                                                    | Leaves for                                                                                       |
| ----------------- | ------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------ |
| `Idle`            | Nothing is recording.                                                           | `Preparing` on `startScan()`, or `Failed` when no source is attached.                            |
| `Preparing`       | Checks that 1.5 GB is free and waits up to 15 s for a `NORMAL` tracking sample. | `Mapping`, or `Failed`.                                                                          |
| `Mapping`         | Takes a frame every 250 ms after a 1 s delay.                                   | `Zipping` on `stopScan()` or at 10 minutes; `Idle` when shorter than 10 s; `Failed` on an error. |
| `Zipping`         | Packages the scan; `packagingProgress` runs from 0 to 1.                        | `Finished`, or `Failed`.                                                                         |
| `Finished`        | `MappingData.zip` is ready.                                                     | `Idle` on `saveDraft()`.                                                                         |
| `Failed(failure)` | Nothing was kept. `failure.message` is text the user can act on.                | `Idle` on `acknowledgeFailure()`.                                                                |

While recording, `MappingScanState` also reports `savedFrames`, `blurredFrames` and `discardedFrames`, `showsMotionWarning` (the camera moved or turned too fast), a `tracking` level (`GOOD`, `WEAK` or `LOST`) with the issue behind it, and `autoStopReason` when the SDK stopped the scan by itself.

**Interruptions.** Poses after an interruption are in a different world frame, so a scan never continues across one. Call `reportSourceInterrupted()` from `onPause`, before `super.onPause()`. A scan that has recorded at least 10 s is packaged as it stood; a shorter one fails and asks the user to start again. A scan that is already `Zipping` or `Finished` is still there when the user comes back.

**Saving.** `saveDraft(name)` needs a name of at least 3 characters and a `Finished` scan, and returns a `MappingDraft` (`id`, `name`, coordinates, `frameCount`, `packageBytes`, `packagedAtMillis`, `thumbnailPath`). The coordinates come from the source's `locationProvider`, or are `0, 0, 0` without one. `discardScan()` deletes the scan from any phase.

***

## Drafts and upload

```kotlin
lifecycleScope.launch {
    repeatOnLifecycle(Lifecycle.State.STARTED) {
        combine(mapping.drafts, mapping.uploads, ::Pair).collect { (drafts, uploads) -> render(drafts, uploads) }
    }
}

uploadButton.setOnClickListener { mapping.upload(draft.id) }       // also "Try again" and "Retry now"
deleteButton.setOnClickListener { mapping.deleteDraft(draft.id) }  // cancels an upload in progress
override fun onResume() { super.onResume(); mapping.resumeUploads() }
```

`drafts` lists the scans saved on this device and not yet uploaded, newest first. `uploads` maps a draft id to its `MappingUploadState`:

| State                 | Meaning                                                                                                                            |
| --------------------- | ---------------------------------------------------------------------------------------------------------------------------------- |
| *(no entry)*          | Idle. A successful upload removes the entry and the draft with it.                                                                 |
| `Preparing`           | Asking the service for an upload ticket.                                                                                           |
| `Uploading(fraction)` | Sending `MappingData.zip`, from 0 to 1.                                                                                            |
| `Waiting(reason)`     | Queued, not transferring: a retry countdown, a draft parked until the app is opened again, or waiting for the SDK to authenticate. |
| `Failed(message)`     | Not retried on its own. `upload()` tries again and `dismissUploadFailure()` clears the entry.                                      |

* **Retries.** A dropped connection, HTTP 408, 429 or 5xx, or an expired upload URL is retried 5 times, after 10, 20, 40, 80 and 160 s. The draft is then parked until `resumeUploads()`.
* **Authentication.** Uploads use the SDK's tokens, from your client credentials or [token provider](https://docs.multiset.ai/native-sdk/android-native/api-reference/authentication.md#token-provider). When those are refused, the draft waits and resumes after the next successful `initialize()`. A token provider that fails is retried like a dropped connection.
* **No duplicate maps.** A retry re-uploads to the map the first attempt created.
* **In-process uploads.** Android has no background transfer service here: the upload runs while your app's process runs, and the queue survives a restart. `initialize()` resumes queued uploads after each successful authentication; also call `resumeUploads()` from `onResume` of the screens a user returns to.

***

## Sample app screens

| Screen                        | What it does                                                                                                                                                |
| ----------------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------- |
| Home: **Mapping** card        | "Create Map" and "Draft Maps", with a badge counting saved drafts.                                                                                          |
| `MappingInstructionsActivity` | "Before you scan": capture tips, with "Don't show this again".                                                                                              |
| `MapScanActivity`             | Landscape scan screen: record and stop, a timer, tracking guidance, a "Move slower" warning and live coverage points, then a name card and upload progress. |
| `DraftMapsActivity`           | The drafts saved on the device, each with a thumbnail, frame count, size, scan date and upload status, plus Upload, Retry and Delete.                       |

***

## Related

* [Android Native Overview](https://docs.multiset.ai/native-sdk/android-native.md)
* [FrameSource and Sessions](https://docs.multiset.ai/native-sdk/android-native/api-reference/framesource.md)
* [Mobile Map Upload](https://docs.multiset.ai/fundamentals/rest-api-docs/map-upload/mobile-map-upload.md)


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation by asking a question.

Perform an HTTP GET request on the following URL with the `ask` and `goal` query parameters:

```
GET https://docs.multiset.ai/native-sdk/android-native/api-reference/map-scanning.md?ask=<question>&goal=<user_goal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is what the user is ultimately trying to achieve, the reason they need the answer. Sharing it helps GitBook give you a better, more relevant answer. A goal is most helpful when it describes the outcome the user wants rather than restating the question. For example, with `ask=how do I create an API token`, a goal like `automate deployments from our CI pipeline` lets GitBook tailor the answer to that use case.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
