Skip to content

Instantly share code, notes, and snippets.

@rolandostar
Last active December 21, 2020 17:58
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 rolandostar/786148925d07ac3988c41fce393e8974 to your computer and use it in GitHub Desktop.
Save rolandostar/786148925d07ac3988c41fce393e8974 to your computer and use it in GitHub Desktop.
Get clipboard content when entering activity
/*
According to the Android lifecycle, clipboard contents cannot be accesed in either onCreate, onResume and neither onRestart.
As such, they can only be accessed when the activity's layout is fully formed
*/
override fun onWindowFocusChanged(hasFocus: Boolean) {
super.onWindowFocusChanged(hasFocus)
if (hasFocus) {
val textToPaste: String = clipboard?.primaryClip?.getItemAt(0)?.text.toString().trim()
Log.d(TAG, textToPaste)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment