1

I would like to know how I can be able to change the value of a specific data copied into my clipboard to my own set value.

So for instance, if the application notices that a phone number had been copied into clipboard, it could then change it to a set phone number be me.

Ps: I'm very new to android development and Java coding.

ODAFE
  • 11
  • 3

1 Answers1

1

Getting data from the clipboard should look like this :

ClipboardManager clipboard = (ClipboardManager) getSystemService(Context.CLIPBOARD_SERVICE);
ClipData.Item item = clipboard.getPrimaryClip().getItemAt(0);
pasteData = item.getText();

You do have to check a few things about pasteData to use it properly : is it text ? is it null ? ...

Setting a value in the clipboard should look like this :

ClipData clip = ClipData.newPlainText("simple text", "Hello, World!");
clipboard.setPrimaryClip(clip);

You don't have to change an existing value, just create a new one.

This is all just a rough explanation as I don't really know what your use case is but I recommend you check out this documentation for more details : https://developer.android.com/guide/topics/text/copy-paste#java

HelloWorld
  • 26
  • 5