Sazzad Hissain Khan
Sazzad Hissain Khan

Reputation: 40196

Communication between Native App and Chrome Custom Tab (CCT)

When I use Android WebView there are ways to communicate between web-app and native with JS interface call as well as JS Injection call. I wonder if there in any work around to communicate between Android native app and Chrome Custom Tab (CCT) by any mean?

I know for security reason Google does not added bridging feature in CCT and TWA. But in Google I/O, they declared that there are limited ways of Web/Native bridging (refer the below figure). I wonder what are the ways as well as where can I find guidelines regarding these limited bridging?

Update 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>

When I am calling abc://abc.oauth.com in browser it does not open my activity. Its opening google search.

Update 2

Finally I got the query params key/value with below code successfully,

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")
        }
    }
}

Thanks a lot @Rahul for guiding me onwards.

Upvotes: 5

Views: 3797

Answers (1)

Rahul Khurana
Rahul Khurana

Reputation: 8834

There is a nice tutorial here which show how to create it step by step.

  1. Create a new request token
  2. Get the user to authorize the request token
  3. Create a new session id with the authorized request token

The main idea behind the whole thing is Intent-Filters with category browseable which will get called whenever the redirect URL is called.

<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"/>

Upvotes: 2

Related Questions