I want to copy a string to the user's mobile clipboard but I don't have any idea how I can use clipboard services in jetpack compose, If there is any alternative or any method that we can use to copy text to clipboard please share.
I want to copy a string to the user's mobile clipboard but I don't have any idea how I can use clipboard services in jetpack compose, If there is any alternative or any method that we can use to copy text to clipboard please share.
You can set and get text using LocalClipboardManager
val clipboardManager: ClipboardManager = LocalClipboardManager.current
var text by remember { mutableStateOf("")}
Column(modifier = Modifier.fillMaxSize()) {
TextField(value = text, onValueChange = {text = it})
Button(onClick = {
clipboardManager.setText(AnnotatedString((text)))
}) {
Text("Copy")
}
Button(onClick = {
clipboardManager.getText()?.text?.let {
text = it
}
}) {
Text("Get")
}
}