/**
* Method to code text in clip board
*
* @param context context
* @param text text what wan to copy in clipboard
* @param label label what want to copied
*/
public static void copyCodeInClipBoard(Context context, String text, String label) {
if (context != null) {
ClipboardManager clipboard = (ClipboardManager) context.getSystemService(CLIPBOARD_SERVICE);
ClipData clip = ClipData.newPlainText(label, text);
if (clipboard == null || clip == null)
return;
clipboard.setPrimaryClip(clip);
}
}
fun copyToClipBoard(context: Context, message: String) {
val clipBoard = context.getSystemService(Context.CLIPBOARD_SERVICE) as ClipboardManager
val clipData = ClipData.newPlainText("label",message)
clipBoard.setPrimaryClip(clipData)
}
import android.content.ClipboardManager
val clipBoard = getSystemService(Context.CLIPBOARD_SERVICE) as ClipboardManager
val clipData = ClipData.newPlainText("label","Message to be Copied")
clipBoard.setPrimaryClip(clipData)
private fun copyTextToClipboard(copyText: String) {
val clipboardManager = requireActivity().
getSystemService(CLIPBOARD_SERVICE) as
android.content.ClipboardManager
val clipData = ClipData.newPlainText("userLabel" ,copyText.trim())
clipboardManager.setPrimaryClip(clipData)
}
fun String.copyToClipboard(context: Context) {
val clipBoard = context.getSystemService(Context.CLIPBOARD_SERVICE) as ClipboardManager
val clipData = ClipData.newPlainText("label",this)
clipBoard.setPrimaryClip(clipData)
}