Spren Vision Android SDK
The Android SDK is in Alpha. We're working quickly to expand our support in the heterogeneity of Android devices.
Device Support and Recommendations
Compatible Devices (Tested)
There may be other compatible, but untested Android devices that are not contained in this list.
- Google Pixel 3XL, 4, 4a, 5, 6*, 6 Pro*, 7*, 7 Pro*
- Xiaomi Redmi 9, Note 10 Pro
- Huawei Mate 20
- Samsung Galaxy Note 9, A51, S9, S10, S10+, S20 FE, S21 Ultra, S22, S22+, S22 Ultra
- Motorola Moto G 5G Plus (2020 model)
- LG Velvet
- OnePlus 7 Pro, 9 5G
*Devices with an asterisk are ones that use the wide angle camera for readings. All other devices use the default camera.
Incompatible Devices (Tested)
- Huawei P20 Lite
- Redmi Note 11
- Google Pixel 6a
Currently, we allow users to only perform readings with flash on.
- We recommend using an Android device that is not a low RAM device, has at least 8 cores, and has 192MB or more RAM available to your app.
- 30FPS is acceptable, but for best accuracy and UX, we recommend devices that support 60FPS in CameraX. Note that 60FPS or better may be listed in manufacturer's device specifications, thus, be supported in the native camera app, but be unavailable to CameraX.
- Rub fingertips and hands to warm up
- Ensure adequate room lighting
- Wait a few seconds for reading to initialize
- Visit the Spren Vision Android SDK Maven Repository to install the SDK via the Gradle build tool. We encourage using the latest remote binary available. For more information, see the Android docs for Add build dependencies.
- Add a camera usage permission to your app's Manifest. For more information, Request app permissions.
The open source code is available in the Spren Vision Android SDK GitHub Repository.
Finger Camera Example
Body Composition Example
Layout and Theme
SprenCapture and SprenCore
Here is an example of how to implement the Spren Vision Android SDK in your own app. Refer to the comments throughout the file to see what functions get called at what point.
Breaking changes in 2.x
var autoStart = true (Replace with SprenCapture reset method)
Enable or disable reading autostart. Autostart occurs after 3 seconds of conditions checks compliance.
fun setTorchMode(torch: Boolean): Boolean (Replace with fun turnFlashOn())
Attempts to toggle the torch (flashlight) on as appropriate. Returns the resulting torch mode. Setting the flash off has been disabled.
fun dropComplexity(): Boolean (no need to handle anymore)
This function has been deprecated and will be removed in the next releases.
fun handleOverExposure() (no need to handle anymore)
Attempts to reduce the exposure of the image by lowering the sensor exposure time. This may be called if exposure is non-compliant, i.e, at least 5 frames are over-exposed.
SprenCapture is where you can initialize a camera preview and first configure the camera. This will start a camera preview and image analysis, allow you to add the camera preview to your UI, and handle various other camera controls. Check out the function definitions below!
fun start(): Boolean
Attempts to create a Preview and ImageAnalysis use cases. Returns false when the camera does not support at least 30 FPS. For more information, see the Android docs for CameraX overview.
Stops the Preview and ImageAnalysis use cases
Starts or restarts a reading. Reading will start after 3 seconds of conditions checks compliance. This function needs to be called after fun start(): Boolean method and after subscribing to Spren Events
Attempts to toggle the torch (flashlight) on.
RGBAnalyzer is an ImageAnalysis.Analyzer and handles providing frames to SprenCore.
The SprenCore library provides internal control over readings and allows you to gain information on what's going on internally in the SDK so your UI can be updated accordingly. Here you'll be able to set reading durations, handle progress updates, start and stop readings, and more. Use this library in conjunction with SprenCapture to utilize the full capabilities of Spren SDK.
Subscribes to events when state changes occur, i.e., started, finished, cancelled, and error.
fun stateListener(values: HashMap<String, Any>)
HashMap key: value
- state: SprenState
Subscribes to events when a compliance check is performed. Compliance checks for lens coverage, and exposure are performed once per second.
fun complianceListener(values: HashMap<String, Any>)
HashMap key: value
- name: ComplianceCheck.Name
- isCompliant: Boolean
Subscribes to events when progress updates. Progress ranges from 0 to 99 in integer increments. State change to finished occurs in lieu of progress update at 100.
fun progressListener(values: HashMap<String, Any>)
HashMap key: value
- progress: Int
Unsubscribing events before leaving the flow
Manually start the reading.
Manually stop the reading.
fun getReadingData(context: Context): String?
After Spren transitions to finished, reading data may be retrieved to hit the Spren API for results. See the User and SDK data POST endpoint for more information.
var readingDurationSeconds = 90
Reading duration ≥ 90 seconds or ≤ 240 seconds.
fun Spren.Companion.setReadingDuration(duration: Int)
Set the reading duration. A duration in the range ≥ 90 seconds or ≤ 240 seconds must be provided or the call returns.
If not using SprenCapture
If you'd like to use your own library or code to handle camera configurations and initialization, make sure to reference this section and the RGBAnalyzer section to get more context and see what functions need to be implemented.
fun process(frame: Bitmap, timestamp: Long)
Provide a frame for processing.
Created from ImageProxy e.g.:
val bitmap = imageProxy.image!!.toBitmap()
The ImageProxy format will be PixelFormat.RGBA_8888, which has only one image plane (R, G, B, A pixel by pixel). For more information, Image Analysis.
Compliance checks are run at 1 second intervals as frames are provided, i.e., if internally to SprenCore the time when the frame is received is >1 second later than the last check. For ComplianceCheck.Name:
- LENS_COVERAGE: finger must cover lens with light pressure.
- EXPOSURE: less than 30 frames must have overexposure. A frame is over-exposed when it appears brighter than it should.