improved link handler
This commit is contained in:
parent
18f0e6f502
commit
d5856213af
|
@ -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"
|
||||
|
|
|
@ -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)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue