Skip to content

Instantly share code, notes, and snippets.

@navczydev
Created August 7, 2022 23:51
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save navczydev/03f32ee90debf89f25a6f214fcb56d9a to your computer and use it in GitHub Desktop.
Save navczydev/03f32ee90debf89f25a6f214fcb56d9a to your computer and use it in GitHub Desktop.
val clipboardManager = context.getSystemService(CLIPBOARD_SERVICE) as ClipboardManager
// When setting the clip board text.
val clipData = ClipData.newPlainText(/* label = */ "Sample copy data",/* text = */ context.getString(R.string.clip_preview))
.apply {
description.extras = PersistableBundle().apply {
// only available for Android13 or higher
putBoolean(ClipDescription.EXTRA_IS_SENSITIVE, true)
// use raw string for older versions
// android.content.extra.IS_SENSITIVE
}
}
clipboardManager.setPrimaryClip(clipData)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment