Code example for ClipboardManager

Methods: getPrimaryClip, getPrimaryClipDescription, hasPrimaryClip

2
	} 
	 
	private void checkClipboard() { 
		if (currentUrl != null) {
			clipboardLinkView.setText(currentUrl);
		} else if (clipboard.hasPrimaryClip() && clipboard.getPrimaryClipDescription().hasMimeType(MIMETYPE_TEXT_PLAIN)) {
			// Check that the clip is plain text 
			ClipData.Item item = clipboard.getPrimaryClip().getItemAt(0);
			CharSequence text = item.getText();
			 
			// Check if it's a web url and that we have not previously seen it 
			if (!text.equals(lastUrl) && Patterns.WEB_URL.matcher(text).find() && !text.equals(currentUrl)) {
				Log.d(TAG, "New web url found: " + text);
				 
				lastUrl = currentUrl = text.toString();
				 
				displayClipboard(text);
			} 
		} else { 
			hideClipboard(); 
		}