Skip to content

Instantly share code, notes, and snippets.

@myrickchow32
Created May 9, 2020 06:53
Show Gist options
  • Save myrickchow32/87b762274bdc44c924e8d899e5e86001 to your computer and use it in GitHub Desktop.
Save myrickchow32/87b762274bdc44c924e8d899e5e86001 to your computer and use it in GitHub Desktop.
class SharingActivity : AppCompatActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_sharing)
val isActivityLaunchedFromActionSend = intent?.action == Intent.ACTION_SEND
val isImageData = intent.type?.startsWith("image/") == true
if (isActivityLaunchedFromActionSend && isImageData) {
handleSendImage(intent)
}
}
private fun handleSendImage(intent: Intent) {
(intent.getParcelableExtra<Parcelable>(Intent.EXTRA_STREAM) as? Uri)?.let {
Glide.with(this).load(it).into(imageView)
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment