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.
Asked
Active
Viewed 170 times
0
-
Does this answer your question: [How to Copy Text to Clip Board in Android?](https://stackoverflow.com/questions/19253786/how-to-copy-text-to-clip-board-in-android) – Sambhav. K Apr 24 '22 at 07:39
-
Does this answer your question? [How to Copy Text to Clip Board in Android?](https://stackoverflow.com/questions/19253786/how-to-copy-text-to-clip-board-in-android) – nglauber Apr 26 '22 at 18:03
1 Answers
0
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")
}
}
Thracian
- 13,723
- 7
- 65
- 116