Skip to content

Instantly share code, notes, and snippets.

Forked from mediavrog/gist:5625602
Last active September 30, 2020 16:16
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
What would you like to do?
Filter out Intents you don"t want to show from a IntentChooser dialog. For example your own app, competing apps or just apps you have a share integration by SDK already :)Based on
fun Intent.createChooserFiltered(context: Context, filter: (ResolveInfo) -> Boolean): Intent {
val results = context.packageManager.queryIntentActivities(this, 0)
.filter { filter(it) }
if (results.isNotEmpty()) {
val intents = {
(this.clone() as Intent).apply {
`package` = it.activityInfo.packageName
val chooserIntent = Intent.createChooser(
intents.removeAt(intents.size - 1), null
return chooserIntent
} else {
return Intent.createChooser(this, null)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment