原生应用与Chrome自定义选项卡(CCT)之间的通信

5

当我使用Android的WebView时,有通过JS接口调用和JS注入调用来实现Web应用程序与本地应用程序之间通信的方法。我想知道是否有任何方法可以通过任何方式在Android本机应用程序和Chrome自定义选项卡(CCT)之间进行通信?

我知道出于安全原因,Google没有在CCTTWA中添加桥接功能。但是在Google I/O上,他们宣布有限的Web/Native bridging方法(请参见下图)。我想知道有哪些方法以及在哪里可以找到有关这些有限桥接的指南?

更新1

<activity android:name=".activities.MyResultActivity">
    <intent-filter>
        <action android:name="android.intent.action.VIEW" />
        <category android:name="android.intent.category.DEFAULT" />
        <category android:name="android.intent.category.BROWSABLE" />
        <data android:scheme="abc"
            android:host="abc.oauth.com" />
    </intent-filter>
</activity>

当我在浏览器中调用abc://abc.oauth.com时,它不会打开我的活动。它会打开谷歌搜索。

更新2

最终,我成功地使用以下代码获取了查询参数的键/值:

override fun onCreate(savedInstanceState: Bundle?) {
    super.onCreate(savedInstanceState)

    Log.d(classTag, "MyResultActivity activity is called")

    intent?.data?.let {

        for (key in it.queryParameterNames) {
            val value = it.getQueryParameter(key)
            Log.d(classTag, "MyResultActivity param key: $key, value: $value")
        }
    }
}

非常感谢@Rahul对我提供的指导。


如果您想进行o-auth登录或类似操作,则需要在AndroidManifest.xml文件中注册auth回调。 - Rahul Khurana
我该怎么做呢?那会非常有帮助。 - Sazzad Hissain Khan
Chrome在Android上不支持扩展,因此标签“google-chrome-extension”无关。 - wOxxOm
1个回答

2
这里有一个不错的教程,点击这里可以逐步学习如何创建它。
以下是具体步骤:
  1. 创建一个新的请求令牌
  2. 让用户授权请求令牌
  3. 使用已授权的请求令牌创建一个新的会话ID
整个过程的主要思想是使用Intent-Filters和类别为browseable的深度链接,每当重定向URL被调用时就会被调用。
<intent-filter android:label="@string/filter_view_http_gizmos">
        <action android:name="android.intent.action.VIEW" />
        <category android:name="android.intent.category.DEFAULT" />
        <category android:name="android.intent.category.BROWSABLE" />

<data 
   android:host="callback_param"
   android:scheme="anything"/>

Rahul,好的,我现在会修改为自定义方案。我会尽快更新给你。 - Sazzad Hissain Khan
@SazzadHissainKhan 也请尝试缩短您的链接,避免使用 # - Rahul Khurana
好的,这次我正在使用 abc://abc.oauth.com。我还有一个问题,如果我在浏览器中尝试该URL,它也应该打开我的活动,对吗?但是它没有打开。 - Sazzad Hissain Khan
@SazzadHissainKhan 尝试在Logcat中打印值以获得清晰的参考。 - Rahul Khurana
1
我成功获取了参数,但onNewIntent从未被调用。我在onCreate中得到了它。请查看更新的帖子。 - Sazzad Hissain Khan
显示剩余9条评论

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接