Ellen Spertus
02/11/2020, 7:55 PMprivate fun getIntent(utterance: String): Intent =
IntentRunner.processUtterance(utterance)?.let { intent ->
intent.resolveActivityInfo(packageManager, intent.flags)?.let { activityInfo ->
if (activityInfo.exported) intent else null
}
} ?: Intent(
Intent.ACTION_VIEW,
Uri.parse("${BASE_URL}${URLEncoder.encode(utterance, ENCODING)}")
)
The idea is that I want the bottom Intent
to be returned if either processUtterance()
returns null, resolveActivityInfo()
returns null, or activityInfo.exported
is false. I welcome comments on correctness and style.trevjones
02/11/2020, 8:00 PMEllen Spertus
02/11/2020, 8:05 PMtrevjones
02/11/2020, 8:11 PMIntentRunner.processUtterance(utterance)?.takeIf { it.resolvesToExportedActivity() }
?: Intent(ACTION_VIEW, Uri.parse("${BASE_URL}${URLEncoder.encode(utterance, ENCODING)}"))
fun Intent.resolvesToExportedActivity() =
resolveActivityInfo(packageManager, flags)?.exported == true