Send form submissions to Formclick from Android apps written in Kotlin, with Jetpack Compose or Views.
It has the same API as @formclick/react-native and the formclick Flutter package: a stateless Formclick client, plus a FormclickSubmitter that exposes loading, success and error state as a StateFlow. It uses HttpURLConnection and Android's built-in org.json. The only dependency is kotlinx-coroutines.
- Android API 21+ (minSdk 21), Kotlin 1.9+, Java 17 toolchain
- Internet permission in
AndroidManifest.xml:
<uses-permission android:name="android.permission.INTERNET" />// app/build.gradle.kts
dependencies {
implementation("io.formclick:formclick-android:0.1.0")
}Get your access key from the Formclick dashboard. Every example below uses YOUR_ACCESS_KEY.
class ContactViewModel : ViewModel() {
val form = FormclickSubmitter()
fun send(name: String, email: String) = viewModelScope.launch {
runCatching {
form.submit("YOUR_ACCESS_KEY", mapOf("name" to name, "email" to email))
}
}
}
@Composable
fun ContactScreen(vm: ContactViewModel = viewModel()) {
val state by vm.form.state.collectAsState()
var name by remember { mutableStateOf("") }
var email by remember { mutableStateOf("") }
Column(Modifier.padding(16.dp)) {
OutlinedTextField(name, { name = it }, label = { Text("Name") })
OutlinedTextField(email, { email = it }, label = { Text("Email") })
Button(onClick = { vm.send(name, email) }, enabled = !state.loading) {
Text(if (state.loading) "Sending…" else "Send")
}
if (state.success) Text("Sent!", color = Color(0xFF16A34A))
state.error?.let { Text(it.message.orEmpty(), color = MaterialTheme.colorScheme.error) }
}
}viewLifecycleOwner.lifecycleScope.launch {
viewLifecycleOwner.repeatOnLifecycle(Lifecycle.State.STARTED) {
vm.form.state.collect { state ->
sendButton.isEnabled = !state.loading
statusText.text = when {
state.success -> "Sent!"
state.error != null -> state.error.message
else -> ""
}
}
}
}val result = Formclick().submit(
formId = "YOUR_ACCESS_KEY",
data = mapOf("name" to "Jane", "email" to "jane@example.com", "topics" to listOf("billing")),
)
println("${result.success} ${result.message}")submit is a suspend function that runs on Dispatchers.IO, so it's safe to call from the main thread inside a coroutine. Field values can be strings, numbers, booleans, null, or lists of those.
submit throws a FormclickException:
| Type | When |
|---|---|
MissingAccessKey |
formId is blank |
Server(status, serverMessage) |
The server returned a non-2xx status, such as an invalid key or a spam block |
Network(cause) |
No connection or a timeout |
val client = Formclick(
submitBaseUrl = "https://api.formclick.io/submit", // default
headers = mapOf("X-App-Version" to "1.2.0"),
timeoutMillis = 15_000,
)
val form = FormclickSubmitter(
client = client,
onSuccess = { Log.d("Formclick", "Sent: $it") },
onError = { Log.w("Formclick", "Failed", it) },
)gradle test # runs against a local mock server, no network calls
gradle publishToMavenLocalMIT © Formclick