Detect copied text

4

How to perform an action whenever someone copies some text in the keyboard of Android? And would you have to use a service to let it run all the time?

    
asked by anonymous 17.01.2016 / 22:33

1 answer

3

You are looking for method addPrimaryClipChangedListener of ClipboardManager . It receives as parameter ClipboardManager.OnPrimaryClipChangedListener .

Assuming you're familiar with Listeners, the code looks something like this:

final ClipboardManager gerenciadorDeAreaDeTransferencia = 
        (ClipboardManager) getSystemService(CLIPBOARD_SERVICE);

gerenciadorDeAreaDeTransferencia.
    addPrimaryClipChangedListener(new OnPrimaryClipChangedListener() {
                    @Override
                    public void onPrimaryClipChanged() {
                        // seu código
                    }
                }
    );

Note that this only works from the API 11.

About running in the background, you'll probably depend on a service, yes, but the details of that are subject to another question.

    
18.01.2016 / 01:57