Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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: ...

like image 921
user2977452 Avatar asked Nov 13 '13 20:11

user2977452


People also ask

What is Android clipboard?

Android provides the clipboard framework for copying and pasting different types of data. The data could be text, images, binary stream data or other complex data types. Android provides the library of ClipboardManager and ClipData and ClipData.

How do I paste text from clipboard Android?

By using a clipboard on Android, you can create a collection of text clips and images and paste them into other apps. Tap the Clipboard icon in the top row of Gboard to see all the recently copied snippets and paste them with a tap.

How do I turn off copy and paste on my Android?

Open the Gboard Settings on your phone. You can do it either by opening the Gboard app or by long-pressing the comma and tapping the Settings icon. In Settings, click on the Clipboard option. Here, turn off the toggle for Clipboard.


Video Answer


2 Answers

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:\n" + 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

like image 191
Carlos Carrizales Avatar answered Oct 14 '22 12:10

Carlos Carrizales


for monitor Clipboard in android you need a service for monitoring clipboard and this service should be define in manifest. your clip board service is here

https://github.com/twaddington/Android-Clipboard-Monitor/blob/master/src/com/example/clipboardmonitor/service/ClipboardMonitorService.java

and manifest define is in the below

<service
        android:name=".service.ClipboardMonitorService"
        android:label="Clipboard Monitor"
        android:exported="false"/>
like image 22
Mahdi Azadbar Avatar answered Oct 14 '22 11:10

Mahdi Azadbar