Skip to content

Instantly share code, notes, and snippets.

@rolandostar
Last active October 24, 2024 02:39
Show Gist options
  • 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)
}
}
@rockyfjord
Copy link

Dude, thanks for the assist!

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