Blog Infos
In this article, we will explore Android 13’s new clipboard UI, as well as privacy improvements 📋
Android 13 introduces a new UI for confirmation whenever data is added to the clipboard.
This new confirmation includes the following features
- ✅ Confirms the content was successfully copied.
- Provides a preview of the copied content.
Copy sensitive content to the clipboard
- ClipData’s ClipDescription must be flagged if the app allows users to copy sensitive information to the clipboard.
A flag to pass to Clipdata’s clip description to flag sensitive content:
ClipDescription.EXTRA_IS_SENSITIVE
- This should be done before calling
setPrimaryClip(ClipData clip)
Sensitive content implementation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
Demo 📋
-
Non-Sensitive content
Non-sensitive content
- Sensitive content
Sensitive content
Job Offers
😊😊 👏👏👏👏 HAPPY CODING 👏👏👏👏 😊😊
Stay in touch
This article was originally published on proandroiddev.com on August 08, 2022