I am writing code to copy specific content on any event.
Android provides clipboard-based framework to do this task.
Clipboard is represented by ClipboardManager class. To instantiate it, we need to call getSystemService(CLIPBOARD_SERVICE)
Then we create ClipData object to add data to the clipboard.
We have some ClipData methods like newPlainText(label, text),newUri(resolver, label, URI) and newIntent(label, intent)
Below is the codeS
String mWorkingUrl = mUrl+"/"+mWebUserName;
android.content.ClipboardManager clipboard = (android.content.ClipboardManager)this.getSystemService(Context.CLIPBOARD_SERVICE);
android.content.ClipData clip = android.content.ClipData.newPlainText("Copy",mWorkingUrl);
Toast.makeText(getApplicationContext(), "Copied", Toast.LENGTH_SHORT).show();
clipboard.setPrimaryClip(clip);
0 Comment(s)