Last active
October 24, 2024 02:39
-
-
Save rolandostar/786148925d07ac3988c41fce393e8974 to your computer and use it in GitHub Desktop.
Get clipboard content when entering activity
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
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
Dude, thanks for the assist!