GoogleChrome / GoogleChrome/android-browser-helper

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.

Open
#531 0 comments 2 reactions 0 assignees View on GitHub
Dominant language
Java
Stars
832
Forks
370
Avg merge
1d 3h
Merged PRs (30d)
6

Description

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

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.