From d5856213affd4f8191ca9a91db6b2f1dae10bed7 Mon Sep 17 00:00:00 2001 From: Mariotaku Lee Date: Wed, 19 Apr 2017 01:09:38 +0800 Subject: [PATCH] improved link handler --- .../kotlin/org/mariotaku/twidere/util/IntentUtils.kt | 12 +----------- .../org/mariotaku/twidere/util/OnLinkClickHandler.kt | 6 ++++-- 2 files changed, 5 insertions(+), 13 deletions(-) diff --git a/twidere/src/main/kotlin/org/mariotaku/twidere/util/IntentUtils.kt b/twidere/src/main/kotlin/org/mariotaku/twidere/util/IntentUtils.kt index c7e3adbe4..96f9fec45 100644 --- a/twidere/src/main/kotlin/org/mariotaku/twidere/util/IntentUtils.kt +++ b/twidere/src/main/kotlin/org/mariotaku/twidere/util/IntentUtils.kt @@ -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" diff --git a/twidere/src/main/kotlin/org/mariotaku/twidere/util/OnLinkClickHandler.kt b/twidere/src/main/kotlin/org/mariotaku/twidere/util/OnLinkClickHandler.kt index 0af06db0f..ca6c4c8eb 100644 --- a/twidere/src/main/kotlin/org/mariotaku/twidere/util/OnLinkClickHandler.kt +++ b/twidere/src/main/kotlin/org/mariotaku/twidere/util/OnLinkClickHandler.kt @@ -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) } } }