I am building ClipboardManager app which is used for copying the text and pasting to the app. I used OnPrimaryClipChangedListener to listen the text that is copied to clipboard and I run OnPrimaryClipChangedListener on app service and that will paste the text automatically to my app. But the problem is that when I open ClipboardManager app and copy the text from own app, it again trigger OnPrimaryClipChangedListener and paste the data again. How to filter the text that is copied from ClipboardManager app or any other app? If that copied from our own app then discard else save the data to ClipboardManager database.
Asked
Active
Viewed 1,006 times
-1
-
you need root access. – rupinderjeet Jan 15 '17 at 06:50
-
1My phone is not rooted, but some other app related to clipboardmanager work perfectly.. While text copy from any browser it will trigger app and save that text automatically. – Rabindra Acharya Jan 15 '17 at 06:53
1 Answers
2
private OnPrimaryClipChangedListener listener = new OnPrimaryClipChangedListener() {
public void onPrimaryClipChanged() {
performClipboardCheck();
}
};
private void performClipboardCheck {
ClipboardManager cb = (ClipboardManager) getSystemService(CLIPBOARD_SERVICE);
if (cb.hasPrimaryClip()) {
ClipData cd = cb.getPrimaryClip();
cd.getItemAt(0).getText()
}
};
from Permanently listen to Clipboard changes
That is probably what you want, that also means this is a duplicate...