← All articlesMobile applications

How to hide sensitive text in Android clipboard previews and verify pasting

When copying a password or bank card details, it is important to keep them out of the system clipboard preview. Android lets you mark clipboard content as sensitive for this purpose. The developer’s task has two parts: hide the text in the visual confirmation and preserve the original value for pasting. This article explains the setup and proposes acceptance checks using entirely fictional strings in your own app.

Identify values that need a hidden preview

Start with the copy actions available to users. Passwords and bank card details are sensitive content: copying them requires the appropriate flag. List these actions in your app so the fix covers every intended copy path, rather than just one button.

The protection here concerns the distinction between clipboard content and its system display. On Android 13 and higher, the flag prevents sensitive text from appearing in the visual copy confirmation. The text itself needs a separate check: a hidden preview does not prove that the correct value reached the clipboard.

Set the flag before passing the clip to the system

For a text string, create a clip with ClipData.newPlainText(). Then add a PersistableBundle to its description with the boolean sensitivity flag set to true. Assign this bundle of additional data to description.extras. Finish preparing the description before calling ClipboardManager.setPrimaryClip().

When compiling with SDK API 33 or higher, use the ClipDescription.EXTRA_IS_SENSITIVE key. For compile SDK API 32 or lower, the documentation specifies the string key android.content.extra.IS_SENSITIVE with the same value of true. This choice depends on the SDK used to build the app, rather than the Android version on the device. The requirement to add the flag applies regardless of the target API level.

Separate expectations by Android version

On Android 13 and higher, the system automatically confirms copying. The documented hiding of sensitive content applies specifically to this system visual confirmation. On earlier versions, the app provides feedback: you cannot require the Android 13 system confirmation to appear on them.

Record the compile SDK and supported device versions separately in your test plan. The former determines how to write the key; the latter determine the expected confirmation behavior. This distinction helps avoid mistaking the absence of the new system interface on an older version for a copying error.

Check ordinary copying first

The following are editorially proposed acceptance tests, not an official Android procedure. Run them only in your own app and use entirely fictional data. For a positive control on a supported device running Android 13 or higher, copy the string DEMO-PUBLIC-ALPHA without the sensitivity flag.

Check the system confirmation and its preview of this string, then paste it into your own test field. To paste plain text, the app retrieves the clip and extracts the text through getText(). The preservation criterion is an exact match between the field’s value and DEMO-PUBLIC-ALPHA. The appearance of a confirmation alone is insufficient: it does not replace comparing the pasted result.

Check the hidden preview and paste accuracy separately

Create another text clip containing the entirely fictional value DEMO-SECRET-ALPHA. Set the sensitivity flag in description.extras before setPrimaryClip(). On Android 13 and higher, check that the system preview does not reveal this string. Then paste the content into your own test field and compare it with the complete original value.

Success requires both conditions: the preview hides the text, and the field contains exactly DEMO-SECRET-ALPHA after pasting. An empty field, an altered string, or exposed text means the check has failed. The absence of a notification about reading the app’s own clip is not an error: the system does not show this notification when an app retrieves ClipData that it created.

Cover all copy actions and limitations

Repeat the test for the app’s intended password and payment data copy actions, substituting only fictional strings. Check that the description of every created clip contains the boolean flag set to true. Then check preview hiding on Android 13 and higher and paste accuracy on supported versions. For earlier versions, also assess the feedback provided by the app: in this proposed test, it should not reveal the fictional secret.

The flag controls how the preview is displayed. It does not prohibit reading the clipboard or prove that copied data has been deleted. On versions below Android 10, background apps can read clipboard content; the sensitivity flag does not resolve this platform limitation. A successful test confirms the observed behavior of the tested scenario, rather than the overall security of the data.

Prioritize fixes

First, fix sensitive-value copy actions where the flag is missing or set after setPrimaryClip(). Then confirm two results using fictional data: the text is absent from the system preview on Android 13 and higher, and the pasted value matches exactly. Next, check the other supported versions, accounting for how they confirm copying.

If your product has a website or web component, you can start with a free audit of that part through CheckMyApp. Perform the Android checks described here separately in your own app: they provide specific acceptance criteria for the copy feature.

Sources and documentation

  1. Secure Clipboard Handling
  2. Copy and paste
CheckMyApp

Check your application’s security.

Enter your web application address and email. Get a free preliminary report and choose the depth of analysis.

Check for free