Skip to content

The attempt to establish a session with the browser through Custom Tabs or TWA (Trusted Web Activity) failed, and the session return was always null on some devices. #531

@ying-dong-elma

Description

@ying-dong-elma

Describe the bug
After upgrading the Android compileSdk version to 35, we encountered an issue when using androidbrowserhelper v2.3.0: establishing a session with the browser via Custom Tabs or Trusted Web Activity (TWA) consistently fails, with newSession returning null. This problem did not occur with compileSdk 34. The frequency of session failures has noticeably increased after the upgrade.

When using androidbrowserhelper v2.5.0 with compileSdk 35, the session occasionally succeeds and the app can be launched, but the issue still persists intermittently.

To Reproduce
Steps to reproduce the behavior:

  1. After the app is installed, when relaunch app, "newSession" returns null

Expected behavior
var session = client.newSession(CustomTabsCallback(), 96375)
Expect the session not to be null!

Code Snippets
class TwaCustomTabsServiceConnection(
private val activity: Activity,
private val appLink: Uri?,
private val listener: TwaListener
) : CustomTabsServiceConnection() {
override fun onServiceDisconnected(p0: ComponentName?) {
Log.i(this.javaClass.name, p0.toString())
}

override fun onCustomTabsServiceConnected(name: ComponentName, client: CustomTabsClient) {
    var session = client.newSession(CustomTabsCallback(), 96375)
    if (session == null) { // Roll back to the old method
        session = client.newSession(CustomTabsCallback())
    }
    if (session == null) {
        // If both methods return null, it indicates that the browser does not support
        // or the service is abnormal and can only prompt the user
        listener.onNullSession()
        return
    }

    val uri = appLink ?: Uri.parse(BuildConfig.WEB_URL)
    Log.d("TWALink", uri.toString())
    val builder = TrustedWebActivityIntentBuilder(uri)
    val intent = builder.build(session).intent
    activity.startActivity(intent)
    listener.isTwaLaunched = true
}

}

Smartphone (please complete the following information):

  • Device: Pixel 7a
  • OS: Android 15
  • Browsers Installed : Chrome
  • Browser Versions Chrome version: 136.0.7103.127
  • android-browser-helper library version 2.5.0

Online users have reported the same issue. The following is the user's device
Galaxy S24FE
Android14
Google Chrome
android-browser-helper library version 2.3.0

Sharp AQUOS
Android15
android-browser-helper library version 2.3.0

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions