Skip to content

Instantly share code, notes, and snippets.

@tizisdeepan
Last active April 22, 2019 08:42
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tizisdeepan/52962b79883696dfedde7e13f0614806 to your computer and use it in GitHub Desktop.
Save tizisdeepan/52962b79883696dfedde7e13f0614806 to your computer and use it in GitHub Desktop.
A Clip Board utility for copying contents to Clip Board.
import android.content.ClipData
import android.content.ClipboardManager
import android.content.Context
import android.widget.Toast
object ClipBoardManager {
fun copy(ctx: Context, text: String, message: String = "") {
val myClipboard = ctx.getSystemService(Context.CLIPBOARD_SERVICE) as ClipboardManager
val myClip = ClipData.newPlainText(message, text)
myClipboard.primaryClip = myClip
if (message.isNotEmpty() && text.isNotEmpty()) Toast.makeText(ctx, message, Toast.LENGTH_SHORT).show()
}
}
@tizisdeepan
Copy link
Author

tizisdeepan commented Apr 22, 2019

USAGE

ClipBoardManager.copy(
    Context Reference, 
    Text to be copied, 
    Text to be displayed as a Toast message indicating that the content has been copied to clipboard
)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment