1

Is there a way to intercept app-wide copying to the clipboard in order to implement an app-only clipboard? I'm aware of ClipboardManager.OnPrimaryClipChanged but that is (1) system-wide, and (2) received AFTER the copying is done. I want to provide a local only clipboard to ensure the contents are kept secure within the app only.

I would rather not create my own ContextualActionBar to provide my own copy button as that would have to be done on every single screen. Thoughts anyone?

Daniel Ochoa
  • 1,792
  • 1
  • 16
  • 22

1 Answers1

0

Instead of disabling the clipboard, just listen to the OnPrimaryClipChanged event. Save the content of the clipboard inside your listener, then clear the system wide clipboard.

Pseudo code (Does not compile):

void OnPrimaryClipChanged (String text) {
     MyLocalClip.save(text);
     ClipboardManager.setText("");
}

Another option is to clear the clipboard inside the onPause method of your main activity, so when the user quits the app - the clipboard is empty.

  • The problem is when it gets added there then any other Service listening in the background from other apps would also receive that callback and have access to what was copied in there. – Daniel Ochoa Sep 05 '15 at 21:48