Ian Vink
Ian Vink

Reputation: 68800

Android: Prevent Clipboard Copy of Text

Our application requires that the text displayed in TextViews or WebViews is not copyable. Can we disable the copy function for controls in an activity or application?

Upvotes: 2

Views: 4561

Answers (4)

Yahel
Yahel

Reputation: 8550

For some reason none of the other answers worked for me so here is my take on it. I specifically used it on a Webview :

webview.setOnCreateContextMenuListener(new OnCreateContextMenuListener() {

            public void onCreateContextMenu(ContextMenu menu, View v,
                    ContextMenuInfo menuInfo) {
                menu.clear();

            }
        });

Hope it helps someone.

Upvotes: 0

su.k.bha
su.k.bha

Reputation: 1

The below worked for me:

textView.setLongClickable(false);

Upvotes: 0

TeaCupApp
TeaCupApp

Reputation: 11452

Try this on TextViews, This mechanism is same in WebView as well.

textView.cancelLongPress();
webView.cancelLongPress();

This should work, as user will not be able to trigger onLongClickListner. Hope this will help to achieve in shortest possible code.

Happy Coding!

Upvotes: 3

Nikola Despotoski
Nikola Despotoski

Reputation: 50588

The copy/paste/select..etc dialog shows up when you do long press on the text area. What if you override onLongClickListener for your view and do nothing inside? Or use ClipboardManager and listen for primary clip changes, if the changes occur then check if there is text or anything else, if true then use setPrimaryClip() with ClipData instance that contains let say empty string. This not might be the best approach, but these pointers maybe will give you the idea.

http://developer.android.com/reference/android/content/ClipboardManager.html

http://developer.android.com/reference/android/content/ClipData.html

Upvotes: 1

Related Questions