Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
379 views
in Technique[技术] by (71.8m points)

clipboardmanager - service - android clipboard listener

I need a simple service (which will run in the background), when user copies anything from the browser or sms etc., there will be a toast showing that text.

example: enter image description here

this service must be run on android 2.1 and later.

Today (from 10:35 AM to now[11:11 PM]) I've been searching the internet and tested several codes, but so far I have not come to a conclusion.

Some users in response to questions like this suggested that the use of the (my-clips) project. I get this, you can download this. But this project is complex and I am confused.

can anyone show me a very simple example please? thank you


Edit:

this is simple app run on background andoird OS. When the user does not open this app and copies any text from the browser or sms etc., this app will be active and show a toast like this: You copy this: ...

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

the way i did it was:

final ClipboardManager clipboard = (ClipboardManager) this.getSystemService(CLIPBOARD_SERVICE);
clipboard.addPrimaryClipChangedListener(new ClipboardManager.OnPrimaryClipChangedListener() {
    public void onPrimaryClipChanged() {
        String a = clipboard.getText().toString();
        Toast.makeText(getBaseContext(), "Copy:
" + a, Toast.LENGTH_LONG).show();
    }
});

do it this way without service, add to manifest or anything, just open your app first then close it, and copy the text from anywhere to copy and show up in your app


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...