最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

android - "Passing" a url from a chrometab to a webview - Stack Overflow

programmeradmin0浏览0评论

I am trying to setup google payment via chrometab in a project, and despite it opening properly, I cannot find a way to, upon closing, inform the webview the chrometab is above, about the current url (/success or /failure).

Chrometab seems to not provide a callback, and intents, unless my fault, do not work

Any help?

enum class BrowserMethods {
    CHROME_TAB, BROWSER
}

internal fun openCustomTab(
    context: Context,
    methods: BrowserMethods = BrowserMethods.CHROME_TAB,
    url: String,
) {
    val uri = Uri.parse(url)

    when (methods) {
        BrowserMethods.CHROME_TAB ->
            try {
                openChromeTab(
                    context = context,
                    uri = uri
                )
            } catch (e: Exception) {
                openBrowser(
                    context = context,
                    uri = uri
                )
            }

        BrowserMethods.BROWSER ->
            openBrowser(
                context = context,
                uri = uri
            )
    }

}

private fun openChromeTab(
    context: Context,
    uri: Uri
) {
    val intent: CustomTabsIntent = CustomTabsIntent
        .Builder()
        .setShareState(CustomTabsIntent.SHARE_STATE_OFF)
        .build()

    intent.launchUrl(context, uri)
}

private fun openBrowser(
    context: Context,
    uri: Uri
) {
    val intent = Intent(Intent.ACTION_VIEW, uri)
    context.startActivity(intent)
}
发布评论

评论列表(0)

  1. 暂无评论