1. Android. Text. clipboardmanager
API level1, an interface without data changes, needs to be simulated. The implementation of this method is complicated and requires a service to be started for a long time. Compare the content of the clipboard with the content read last time. If the content is different, the Clipboard data is changed .. If you have not read the clipboard before, it is an empty string by default. It is best to store this value on the SD card, for example, sharedpreference. Stored in static variables ..
How to read clipboard content
private String getClipboardText() { ClipboardManager clipboard = (ClipboardManager) getSystemService(Context.CLIPBOARD_SERVICE); String text = ""; try { if (clipboard != null && clipboard.hasText()) { CharSequence tmpText = clipboard.getText(); clipboard.setText(tmpText); if (tmpText != null && tmpText.length() > 0) { text = tmpText.toString().trim(); } } } catch (Exception e) { e.printStackTrace(); text = ""; } return text; }
2. Android. content. clipboardmanager
API level11 is inherited from Android. Text. clipboardmanager and can be used with ready-made interfaces:
Addprimaryclipchangedlistener.