Created
November 5, 2022 13:11
-
-
Save shivam-gupta007/139156a0bfd6cf86b4fdf10631c1d172 to your computer and use it in GitHub Desktop.
This file contains 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
override fun onCreate(savedInstanceState: Bundle?) { | |
super.onCreate(savedInstanceState) | |
setContentView(R.layout.activity_main) | |
when { | |
intent?.action == Intent.ACTION_SEND -> { | |
if ("text/plain" == intent.type) { | |
handleSendText(intent) | |
} else if (intent.type?.startsWith("image/") == true) { | |
handleSendImage(intent) | |
} | |
} | |
intent?.action == Intent.ACTION_SEND_MULTIPLE | |
&& intent.type?.startsWith("image/") == true -> { | |
handleSendMultipleImages(intent) | |
} | |
else -> { | |
// Handle other intents, such as being started from the home screen | |
} | |
} | |
} | |
private fun handleSendText(intent: Intent) { | |
intent.getStringExtra(Intent.EXTRA_TEXT)?.let { | |
// Update UI to display text being shared | |
} | |
} | |
private fun handleSendImage(intent: Intent) { | |
(intent.getParcelableExtra<Parcelable>(Intent.EXTRA_STREAM) as? Uri)?.let { | |
// Update UI to display image being shared | |
} | |
} | |
private fun handleSendMultipleImages(intent: Intent) { | |
intent.getParcelableArrayListExtra<Parcelable>(Intent.EXTRA_STREAM)?.let { | |
// Update UI to display multiple images being shared | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment