0

I would like to prevent the users of my Android application to copy and paste data from my application to anywhere else but within the application itself. Given that the clipboard is one of the more common ways for exposing sensitive data, I am wondering if there is any way to limit the scope of the clipboard, so that it can only be used within the application?

I've already created a solution to prevent copy/paste in the application's text components (TextView, EditText...), but I am looking for a more efficient approach to this problem. I've been thinking about clearing the clipboard on exiting the application, but I don't want to do that, since the user might have important information he/she wants to keep in the clipboard.

Has anyone else faced a similar situation before? Do you have any ideas on how to do this?

Thanks!

deluxe1
  • 737
  • 4
  • 15
  • 'prevent copy/paste in the application's text components (TextView, EditText...)' sounds decent to me.. – Martin Pfeffer May 27 '21 at 13:37
  • 1
    May be You could try this. 1) On launching your app, Get the recent one from Clipboard and store it in Shared Pref. 2) On Exit of the app/Or when your app goes to the background,, Set the same to clipbord – Indra Kumar S May 27 '21 at 13:39
  • @IndraKumarS interesting approach. But the clipboard isn't the last entry only, it can contain more than one entry. Maybe if I could remove all entries after the last one... I will check this out, see if it works – deluxe1 May 27 '21 at 13:43
  • If a user can copy data to the clipboard then the user can also paste this data to a different application `behind the back` of your application. The user does not have to wait for the app to close. – blackapps May 27 '21 at 13:54
  • "is any way to limit the scope of the clipboard, so that it can only be used within the application?" -- you cannot control the system clipboard in this fashion. – CommonsWare May 27 '21 at 13:56

1 Answers1

0

This is not a full solution but you could limit the use of the copy and paste to one time use. This way the sensitive data is not lingering.

 public Class ClipboardUtils{
        public static clear(Context context){
               ClipboardManager clipBoard = (ClipboardManager) context.getSystemService(CLIPBOARD_SERVICE);
               ClipData data = ClipData.newPlainText("", "");
               clipBoard.setPrimaryClip(data);
        }
 }

With an edit text you could do something like this

 EditText et = (EditText) mView.findViewById(R.id.yourEditText);
 et.addTextChangedListener(new TextWatcher() {
          @Override
          public void onTextChanged(CharSequence s, int start, int before, int count) {
             if (count > 2)
                ClipboardUtils.clear(getContext());
          }
          @Override
          public void beforeTextChanged(CharSequence s, int start, int count, int after) {}
          public void afterTextChanged(Editable s) {}
});

sources

Clearing Clipboard Data in Android

Android intercept paste\copy\cut on editText

avalerio
  • 2,072
  • 1
  • 12
  • 11