improved link handler

This commit is contained in:
Mariotaku Lee 2017-04-19 01:09:38 +08:00
parent 18f0e6f502
commit d5856213af
No known key found for this signature in database
GPG Key ID: 15C10F89D7C33535
2 changed files with 5 additions and 13 deletions

View File

@ -194,17 +194,7 @@ object IntentUtils {
}
val intent = Intent(Intent.ACTION_VIEW)
intent.addCategory(Intent.CATEGORY_BROWSABLE)
val testBuilder = Uri.Builder()
testBuilder.scheme(SCHEME_HTTP)
val sb = StringBuilder()
val random = Random()
val range = 'z' - 'a'
for (i in 0..19) {
sb.append(('a' + Math.abs(random.nextInt()) % range))
}
sb.append(".com")
testBuilder.authority(sb.toString())
intent.data = testBuilder.build()
intent.data = Uri.parse("${uri.scheme}://")
return intent.resolveActivity(context.packageManager)?.takeIf {
it.className != null && it.packageName != "android"

View File

@ -181,11 +181,13 @@ open class OnLinkClickHandler(
companion object {
fun openLink(context: Context, preferences: SharedPreferences, uri: Uri) {
val (intent, options) = IntentUtils.browse(context, preferences, uri = uri)
val (intent, options) = IntentUtils.browse(context, preferences, uri = uri,
forceBrowser = false)
try {
ContextCompat.startActivity(context, intent, options)
} catch (e: ActivityNotFoundException) {
// Ignore
Analyzer.logException(e)
DebugLog.w(tr = e)
}
}
}