Coder Social home page Coder Social logo

googlechrome / android-browser-helper Goto Github PK

View Code? Open in Web Editor NEW
655.0 64.0 276.0 1.85 MB

The Android Browser Helper library helps developers use Custom Tabs and Trusted Web Activities on top of the AndroidX browser support library.

License: Apache License 2.0

Java 98.76% Kotlin 0.99% AIDL 0.25%

android-browser-helper's Introduction

Android Browser Helper

CI Status Badge

The Android Browser Helper library helps developers use Custom Tabs and Trusted Web Activities on top of the AndroidX browser support library. It contains default implementations of many of the common tasks a developer will find themselves requiring, for example:

  • Creating a Launcher Activity that simply launches a Trusted Web Activity.
  • Code for choosing an appropriate Custom Tabs provider.
  • Creating an Activity to launch the browser's site settings for a TWA.

Adding Android Browser Helper to an Android project

Android Browser helper is available on the Google Maven. To use it, modify your application's build.gradle and add the library as a dependency, as described below:

dependencies {
    //...
    implementation 'com.google.androidbrowserhelper:androidbrowserhelper:2.4.0'
}

Information for Google Play's data disclosure requirements

The Android Browser Helper library is intended to allow Android applications to interact with browsers on the device. As such, it will share certain types of information with the browser.

Data types collected / shared

Web browsing: URLs handled by the application are shared with the browser when a Custom Tab or a Trusted Web Activity are launched.

URLs are also shared with the browser by certain features like mayLaunchUrl(), so that the browser can speed up loading performance of those pages.

When the WebView fallback feature is enabled by the developer, the application may store the navigation history and browser storage, like cookies on the device.

User location (Optional): The SDK may share location data with the host browser, when the location delegation library is used. Users can control sharing of the location using the Android permission dialogs and the System settings.

Purchase History (Optional): The SDK may share purchase history data with the host browser when the Google Play billing library is used. Only purchases made within the application are shared.

This SDK does not transfer any information over the network. Web browsing information may be stored if the WebView fallback is enabled. The permission to read the location can be managed via the usual Android settings.

Source Code Headers

Every file containing source code must include copyright and license information. This includes any JS/CSS files that you might be serving out to browsers. (This is to help well-intentioned people avoid accidental copying that doesn't comply with the license.)

Apache header:

Copyright 2019 Google LLC

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

    https://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.

android-browser-helper's People

Contributors

andreban avatar build3r avatar demianrenzulli avatar eirage avatar elabadysayed avatar jeevan-shikaram avatar jinsukkim avatar joycetoh8 avatar khatv911 avatar mrajah1 avatar mvano avatar nohe427 avatar notwoods avatar padr31 avatar peconn avatar pshmakov avatar rayankans avatar sayedelabady avatar sclimwi avatar sebastianbenz avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

android-browser-helper's Issues

Add support for Web Share Target API

It is possible to register a PWA (WebAPK) as share target (it happens automatically if share_target is specified in manifest.json) but it does not seem to be supported in TWA at the moment.
This is a huge bummer for us because share data with our PWA/TWA is a central feature.

Google assistant popping up on tap by text.

In PWA mode google assistant don't interact with page. But in TWA mode it act like Chrome Tab and assistant can create very messy experience then users tap on html content.

Issue on Kindle Fire devices

When attempting to use an app built using this project on a Kindle Fire device, the splash screen of the app hangs and then the browser interface is not launched.

I have noticed this in the debug output:
D/TWAProviderPicker: Found TWA provider, finishing search: com.amazon.cloud9

According to this log entry, it appears that Amazon's browser is advertising compatibility. I was surprised by this - I had assumed that a fallback strategy would be employed (in my case a WebView activity). I'm not sure if Amazon's browser actually has support or not.

To Reproduce
Steps to reproduce the behavior:

  1. Build functioning TWA app
  2. Run TWA app on an Amazon device
  3. Observe that TWA experience isn't launched

Expected behavior
Either the TWA experience working or the fallback strategy being employed.

Did this ever used to work
Unknown

Smartphone (please complete the following information):

  • Device: Kindle Fire 7
  • OS: Fire OS 5.3.7.0, Android 5.1.1
  • Browsers Installed: Silk Browser
  • Browser Versions: 79.4.9.3945.136.10
  • android-browser-helper library version: 1.1.0

Add a postMessage demo.

Using postMessage is pretty confusing, we should add a demo for it.

(This is for CCTs, not for TWAs)

Add a demo Notification Delegation with custom notifications

Native notifications allow customisations like different notification sounds. The goal is to setup the Trusted Web Activity project and customise native notifications.

Demonstrating every possible customisation of the native notification API is outside the scope of the demo, as those should be well documented by Android itself.

TwaLauncher does not opens links on Meizu

I'm trying to open link like this:

TwaLauncher(context).launch(Uri.parse(url))

It works good on any devices, except the Meizu

I've tested on Meizu PRO 5. Android 5.1 (SDK: 22)

Maybe I do something wrong. I don't even understand how to enable logging on TwaLauncher to improve the bug report.

I hope for your help. Thank you

TWA is crashing multiple times.

My TWA is crashing multiple times. I am including some error text from play console dashboard. I am not android developer so I can not understand these errors.

Input dispatching timed out (Waiting because no window has focus but there is a focused application that may eventually add a window when it finishes starting up.)

android.support.customtabs.trusted.LauncherActivity

Input dispatching timed out (AppWindowToken{ac22d4d token=Token{d4e34e4 ActivityRecord{7a3d077 u0 com.example.kott/android.support.customtabs.trusted.LauncherActivity t2139}}}, Waiting because no window has focus but there is a focused application that may eventually add a window when it finishes starting up.)

android.support.customtabs.trusted.LauncherActivity
java.lang.RuntimeException: 
  at android.view.InputChannel.nativeReadFromParcel (Native Method)
  at android.view.InputChannel.readFromParcel (InputChannel.java:148)
  at android.view.IWindowSession$Stub$Proxy.addToDisplay (IWindowSession.java:804)
  at android.view.ViewRootImpl.setView (ViewRootImpl.java:755)
  at android.view.WindowManagerGlobal.addView (WindowManagerGlobal.java:359)
  at android.view.WindowManagerImpl.addView (WindowManagerImpl.java:93)
  at android.app.ActivityThread.handleResumeActivity (ActivityThread.java:3834)
  at android.app.ActivityThread.handleLaunchActivity (ActivityThread.java:3009)
  at android.app.ActivityThread.-wrap11 (Unknown Source)
  at android.app.ActivityThread$H.handleMessage (ActivityThread.java:1700)
  at android.os.Handler.dispatchMessage (Handler.java:106)
  at android.os.Looper.loop (Looper.java:192)
  at android.app.ActivityThread.main (ActivityThread.java:6748)
  at java.lang.reflect.Method.invoke (Native Method)
  at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run (RuntimeInit.java:556)
  at com.android.internal.os.ZygoteInit.main (ZygoteInit.java:867)
android.app.RemoteServiceException: 
  at android.app.ActivityThread$H.handleMessage (ActivityThread.java:1922)
  at android.os.Handler.dispatchMessage (Handler.java:102)
  at android.os.Looper.loop (Looper.java:145)
  at android.app.ActivityThread.main (ActivityThread.java:6946)
  at java.lang.reflect.Method.invoke (Native Method)
  at java.lang.reflect.Method.invoke (Method.java:372)
  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run (ZygoteInit.java:1404)
  at com.android.internal.os.ZygoteInit.main (ZygoteInit.java:1199)
java.lang.RuntimeException: 
  at android.view.InputChannel.nativeReadFromParcel (Native Method)
  at android.view.InputChannel.readFromParcel (InputChannel.java:148)
  at android.view.InputChannel$1.createFromParcel (InputChannel.java:39)
  at android.view.InputChannel$1.createFromParcel (InputChannel.java:37)
  at com.android.internal.view.InputBindResult.<init> (InputBindResult.java:68)
  at com.android.internal.view.InputBindResult$1.createFromParcel (InputBindResult.java:112)
  at com.android.internal.view.InputBindResult$1.createFromParcel (InputBindResult.java:110)
  at com.android.internal.view.IInputMethodManager$Stub$Proxy.startInputOrWindowGainedFocus (IInputMethodManager.java:723)
  at android.view.inputmethod.InputMethodManager.startInputInner (InputMethodManager.java:1353)
  at android.view.inputmethod.InputMethodManager.onPostWindowFocus (InputMethodManager.java:1606)
  at android.view.ViewRootImpl$ViewRootHandler.handleMessage (ViewRootImpl.java:4130)
  at android.os.Handler.dispatchMessage (Handler.java:106)
  at android.os.Looper.loop (Looper.java:192)
  at android.app.ActivityThread.main (ActivityThread.java:6748)
  at java.lang.reflect.Method.invoke (Native Method)
  at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run (RuntimeInit.java:556)
  at com.android.internal.os.ZygoteInit.main (ZygoteInit.java:867)
java.lang.SecurityException: 
  at android.os.Parcel.readException (Parcel.java:1620)
  at android.os.Parcel.readException (Parcel.java:1573)
  at android.app.ActivityManagerProxy.getIntentSender (ActivityManagerNative.java:4126)
  at android.app.PendingIntent.getActivity (PendingIntent.java:311)
  at android.app.PendingIntent.getActivity (PendingIntent.java:272)
  at android.support.customtabs.b.a (Unknown Source)
  at android.support.customtabs.b.a (Unknown Source)
  at android.support.customtabs.trusted.LauncherActivity.a (Unknown Source)
  at android.support.customtabs.trusted.LauncherActivity$a.a (Unknown Source)
  at android.support.customtabs.d.onServiceConnected (Unknown Source)
  at android.app.LoadedApk$ServiceDispatcher.doConnected (LoadedApk.java:1223)
  at android.app.LoadedApk$ServiceDispatcher$RunConnection.run (LoadedApk.java:1240)
  at android.os.Handler.handleCallback (Handler.java:739)
  at android.os.Handler.dispatchMessage (Handler.java:95)
  at android.os.Looper.loop (Looper.java:148)
  at android.app.ActivityThread.main (ActivityThread.java:5582)
  at java.lang.reflect.Method.invoke (Native Method)
  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run (ZygoteInit.java:726)
  at com.android.internal.os.ZygoteInit.main (ZygoteInit.java:616)
java.lang.NullPointerException: 
  at android.app.ActivityThread.handleStopActivity (ActivityThread.java:4844)
  at android.app.ActivityThread.-wrap29 (ActivityThread.java)
  at android.app.ActivityThread$H.handleMessage (ActivityThread.java:1845)
  at android.os.Handler.dispatchMessage (Handler.java:102)
  at android.os.Looper.loop (Looper.java:148)
  at android.app.ActivityThread.main (ActivityThread.java:7325)
  at java.lang.reflect.Method.invoke (Native Method)
  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run (ZygoteInit.java:1230)
  at com.android.internal.os.ZygoteInit.main (ZygoteInit.java:1120)
android.view.WindowManager$BadTokenException: 
  at android.view.ViewRootImpl.setView (ViewRootImpl.java:772)
  at android.view.WindowManagerGlobal.addView (WindowManagerGlobal.java:298)
  at android.view.WindowManagerImpl.addView (WindowManagerImpl.java:91)
  at android.app.ActivityThread.handleResumeActivity (ActivityThread.java:4185)
  at android.app.ActivityThread.handleLaunchActivity (ActivityThread.java:3311)
  at android.app.ActivityThread.access$1000 (ActivityThread.java:211)
  at android.app.ActivityThread$H.handleMessage (ActivityThread.java:1705)
  at android.os.Handler.dispatchMessage (Handler.java:102)
  at android.os.Looper.loop (Looper.java:145)
  at android.app.ActivityThread.main (ActivityThread.java:6946)
  at java.lang.reflect.Method.invoke (Native Method)
  at java.lang.reflect.Method.invoke (Method.java:372)
  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run (ZygoteInit.java:1404)
  at com.android.internal.os.ZygoteInit.main (ZygoteInit.java:1199)
java.lang.IllegalArgumentException: 
  at android.os.Parcel.readException (Parcel.java:1971)
  at android.os.Parcel.readException (Parcel.java:1913)
  at android.app.IActivityManager$Stub$Proxy.reportSizeConfigurations (IActivityManager.java:9969)
  at android.app.ActivityThread.reportSizeConfigurations (ActivityThread.java:3093)
  at android.app.ActivityThread.handleLaunchActivity (ActivityThread.java:3036)
  at android.app.ActivityThread.handleRelaunchActivity (ActivityThread.java:4921)
  at android.app.ActivityThread.-wrap19 (Unknown Source)
  at android.app.ActivityThread$H.handleMessage (ActivityThread.java:1702)
  at android.os.Handler.dispatchMessage (Handler.java:105)
  at android.os.Looper.loop (Looper.java:164)
  at android.app.ActivityThread.main (ActivityThread.java:6944)
  at java.lang.reflect.Method.invoke (Native Method)
  at com.android.internal.os.Zygote$MethodAndArgsCaller.run (Zygote.java:327)
  at com.android.internal.os.ZygoteInit.main (ZygoteInit.java:1374)
backtrace:
  #00  pc 000000000004ab94  /system/lib/libc.so (tgkill+12)
  #01  pc 0000000000048333  /system/lib/libc.so (pthread_kill+34)
  #02  pc 000000000001de0d  /system/lib/libc.so (raise+10)
  #03  pc 0000000000019511  /system/lib/libc.so (__libc_android_abort+34)
  #04  pc 000000000001718c  /system/lib/libc.so (abort+4)
  #05  pc 000000000000c62d  /system/lib/libcutils.so (__android_log_assert+112)
  #06  pc 000000000002586f  /system/lib/libhwui.so
  #07  pc 0000000000027277  /system/lib/libhwui.so
  #08  pc 000000000002aa09  /system/lib/libhwui.so (android::uirenderer::renderthread::RenderThread::threadLoop()+80)
  #09  pc 000000000000e429  /system/lib/libutils.so (android::Thread::_threadLoop(void*)+140)
  #10  pc 0000000000069e2d  /system/lib/libandroid_runtime.so (android::AndroidRuntime::javaThreadShell(void*)+80)
  #11  pc 0000000000047e03  /system/lib/libc.so (__pthread_start(void*)+22)
  #12  pc 000000000001a181  /system/lib/libc.so (__start_thread+6)

Add support for fullscreen/immersive mode

android-browser-helper is making the Immersive Mode API easier to use: #95

  1. During the init command, Bubblewrap should use read display attribute from the Web Manifest.
  2. If the display is fullscreen, default the configuration to use immersive mode. Otherwise, default to regular mode.
  3. Ask the developer to confirm the choice.

Links from Gmail mobile app are opening in micro-browser or crashing

Describe the bug
After recent update to last stable version of android-browser-helper we started to observe a bug across many devices that caused crashes or improper behavior that happens when people are opening specific links on the up-to-date Gmail mobile Android app. It is a problem only concerning this mobile mail client, it doesn't appear on Outlook mobile or other clients - there links are opening properly as TWA.

To Reproduce
Steps to reproduce the behavior:

  1. Receive an e-mail on Gmail mobile app that contains a link to TWA-bundled app
  2. Click on that link
  3. Either website will be opened in Chrome micro-browser or it will crash at that point, it won't open it as TWA

Expected behavior
When TWA app is installed on device, such links should always open as existing or new TWA instance.

Did this ever used to work
Earlier android-browser-helper versions and Gmail mobile client app.

Smartphone (please complete the following information):

  • Device: OnePlus 7 Pro
  • OS: Android 10
  • Browsers Installed: Chrome
  • Browser Versions: latest
  • android-browser-helper library version: latest stable
  • Gmail Android client app version: latest stable

restart app after updating a new version

I have raised the issue in stackoverflow

Actually, I have raised the question in this thread But the issue seems can be resolved if users are using the native activity, the app will be restarted then they update a new version.

I am running the app with a custom tab, during the running the app (chrome on custom tab), then I use ADB to install a new version. In this case, maybe the new URL can be updated with a new value, I want to force users to restart the mainActivity with a new URL. However, as I see the users still use the old version (old URL) without any change until they restart the app.

Any way to force users to restart the app with new URL value?

I have tried Broadcast Reciever with "MY_PACKAGE_REPLACED" but it didn't help.

Thanks.

Activity com.google.androidbrowserhelper.launchtwa.LaunchTwaActivity has leaked ServiceConnection

The library (com.google.androidbrowserhelper:androidbrowserhelper:1.1.0) is leaking the ServiceConnection when exiting the activity (see below for the stacktrace). I also checked the elder version (1.0.0), this is also leaking.

How to reproduce:

  • Run e.g. the TWA-CUSTOM-LAUNCHER from the Demos
  • launch one of the instances, e.g. "LAUNCH WITH CUSTOM COLORS"
  • exit the customtab, by pressing back or close
  • then exit the activity, by pressing back
  • In the logcat you will see the activity is leaking the ServiceConnection

Tested on:

  • Emulator: Pixel 3, API 29, x86
  • Samsung Galaxy Tab S3, SM-T820, Android 7.0

Stacktrace:

E/ActivityThread: Activity com.google.androidbrowserhelper.launchtwa.LaunchTwaActivity has leaked ServiceConnection com.google.androidbrowserhelper.trusted.TwaLauncher$TwaCustomTabsServiceConnection@5605265 that was originally bound here
    android.app.ServiceConnectionLeaked: Activity com.google.androidbrowserhelper.launchtwa.LaunchTwaActivity has leaked ServiceConnection com.google.androidbrowserhelper.trusted.TwaLauncher$TwaCustomTabsServiceConnection@5605265 that was originally bound here
        at android.app.LoadedApk$ServiceDispatcher.<init>(LoadedApk.java:1805)
        at android.app.LoadedApk.getServiceDispatcherCommon(LoadedApk.java:1677)
        at android.app.LoadedApk.getServiceDispatcher(LoadedApk.java:1656)
        at android.app.ContextImpl.bindServiceCommon(ContextImpl.java:1721)
        at android.app.ContextImpl.bindService(ContextImpl.java:1650)
        at android.content.ContextWrapper.bindService(ContextWrapper.java:705)
        at androidx.browser.customtabs.CustomTabsClient.bindCustomTabsService(CustomTabsClient.java:76)
        at com.google.androidbrowserhelper.trusted.TwaLauncher.launchTwa(TwaLauncher.java:205)
        at com.google.androidbrowserhelper.trusted.TwaLauncher.launch(TwaLauncher.java:154)
        at com.google.androidbrowserhelper.trusted.TwaLauncher.launch(TwaLauncher.java:173)
        at com.google.androidbrowserhelper.launchtwa.LaunchTwaActivity.launchWithCustomColors(LaunchTwaActivity.java:67)
        at java.lang.reflect.Method.invoke(Native Method)
        at androidx.appcompat.app.AppCompatViewInflater$DeclaredOnClickListener.onClick(AppCompatViewInflater.java:385)
        at android.view.View.performClick(View.java:7125)
        at android.view.View.performClickInternal(View.java:7102)
        at android.view.View.access$3500(View.java:801)
        at android.view.View$PerformClick.run(View.java:27336)
        at android.os.Handler.handleCallback(Handler.java:883)
        at android.os.Handler.dispatchMessage(Handler.java:100)
        at android.os.Looper.loop(Looper.java:214)
        at android.app.ActivityThread.main(ActivityThread.java:7356)
        at java.lang.reflect.Method.invoke(Native Method)
        at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:492)
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:930)

Demo for starting TWA

Hi is it possible to change the start and exit animation of trusted web activity? If yes is there an available demo?

Thank you

Task management tests.

Create tests to ensure TWAs only occupy a single, canonical Task no matter how they are launched.

postMessage support?

I noticed the APIs in CustomTabService for using postMessage, but I couldn't get them to work. And after some searching around I found this patch, suggesting that postMessage is disabled in TWAs:

https://chromium.googlesource.com/chromium/src/+/20891520570f780b13ae9725d9aa5a909338d0a9%5E%21/

But it was back in 2018, so I wanted to check: can I use the native postMessage APIs with TWAs? If not, are there any other strategies for transferring data between the native and web sides?

NullPointerException - CustomTabsSession is required for launching a TWA

We recently launched our TWA application and saw a few of these crashes come in. We are using 0.1.0-alpha1. I have not experienced this issue myself so I have no way of reproducing it.

java.lang.NullPointerException: CustomTabsSession is required for launching a TWA
    at androidx.browser.trusted.TrustedWebActivityIntentBuilder.build(TrustedWebActivityIntentBuilder.java:15)
    at com.google.androidbrowserhelper.trusted.TwaLauncher.launchWhenSplashScreenReady(TwaLauncher.java:2)
    at com.google.androidbrowserhelper.trusted.TwaLauncher.lambda$launchWhenSessionEstablished$2(TwaLauncher.java:1)
    at com.google.androidbrowserhelper.trusted.-$$Lambda$TwaLauncher$wy2yMaTyWzqDYy88T6GKCwq94sM.run
    at com.google.androidbrowserhelper.trusted.splashscreens.PwaWrapperSplashScreenStrategy.onSplashImageTransferred(PwaWrapperSplashScreenStrategy.java:2)
    at com.google.androidbrowserhelper.trusted.splashscreens.-$$Lambda$PwaWrapperSplashScreenStrategy$w9o5iqMEy62ZZ2i_sMAmRiQ7IGw.onFinished
    at com.google.androidbrowserhelper.trusted.splashscreens.SplashImageTransferTask$1.onPostExecute(SplashImageTransferTask.java:3)
    at android.os.AsyncTask.finish(AsyncTask.java:695)
    at android.os.AsyncTask.access$600(AsyncTask.java:180)
    at android.os.AsyncTask$InternalHandler.handleMessage(AsyncTask.java:712)
    at android.os.Handler.dispatchMessage(Handler.java:106)
    at android.os.Looper.loop(Looper.java:214)
    at android.app.ActivityThread.main(ActivityThread.java:7050)
    at java.lang.reflect.Method.invoke(Method.java)
    at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:493)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:965)

Crash on start: Non-browser selected

Describe the bug
While the default system browser (where any link opens by default) is set to an actual browser (Brave, also tried setting to Chrome), for some reason an app that is not a browser and does not appear in the system browser selection (Revolut) is selected as TWA provider which causes a crash on start.

To Reproduce
Launching the app on my phone in debug mode returns these logs before the app crashes:

D/TWALauncherActivity: Using URL from Manifest (https://travelfeed.io/?utm_source=pwa).
D/TWAProviderPicker: Found browser: com.revolut.revolut
    Found browser: com.revolut.revolut
D/TWAProviderPicker: Found no TWA providers, using first browser: com.revolut.revolut
D/AndroidRuntime: Shutting down VM
E/AndroidRuntime: FATAL EXCEPTION: main
    Process: io.travelfeed.twa, PID: 14612
    java.lang.RuntimeException: Unable to start activity ComponentInfo{io.travelfeed.twa/com.google.androidbrowserhelper.trusted.LauncherActivity}: android.content.ActivityNotFoundException: No Activity found to handle Intent { act=android.intent.action.VIEW dat=https://travelfeed.io/... pkg=com.revolut.revolut (has extras) }
        at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3114)
        at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3257)
        at android.app.servertransaction.LaunchActivityItem.execute(LaunchActivityItem.java:78)
        at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:108)
        at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:68)
        at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1948)
        at android.os.Handler.dispatchMessage(Handler.java:106)
        at android.os.Looper.loop(Looper.java:214)
        at android.app.ActivityThread.main(ActivityThread.java:7050)
        at java.lang.reflect.Method.invoke(Native Method)
        at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:494)
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:965)
     Caused by: android.content.ActivityNotFoundException: No Activity found to handle Intent { act=android.intent.action.VIEW dat=https://travelfeed.io/... pkg=com.revolut.revolut (has extras) }
        at android.app.Instrumentation.checkStartActivityResult(Instrumentation.java:2018)
        at android.app.Instrumentation.execStartActivity(Instrumentation.java:1673)
        at android.app.Activity.startActivityForResult(Activity.java:4689)
        at androidx.fragment.app.FragmentActivity.startActivityForResult(FragmentActivity.java:767)
        at android.app.Activity.startActivityForResult(Activity.java:4647)
        at androidx.fragment.app.FragmentActivity.startActivityForResult(FragmentActivity.java:754)
        at android.app.Activity.startActivity(Activity.java:5008)
        at androidx.core.content.ContextCompat.startActivity(ContextCompat.java:251)
        at androidx.browser.customtabs.CustomTabsIntent.launchUrl(CustomTabsIntent.java:331)
        at com.google.androidbrowserhelper.trusted.TwaLauncher.lambda$static$0(TwaLauncher.java:51)
        at com.google.androidbrowserhelper.trusted.-$$Lambda$TwaLauncher$yiLzsm37NbSon1-dZ2dCvDJv8wU.launch(Unknown Source:0)
        at com.google.androidbrowserhelper.trusted.TwaLauncher.launch(TwaLauncher.java:166)
        at com.google.androidbrowserhelper.trusted.LauncherActivity.onCreate(LauncherActivity.java:158)
        at android.app.Activity.performCreate(Activity.java:7327)
        at android.app.Activity.performCreate(Activity.java:7318)
        at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1271)
        at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3094)
        at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3257) 
        at android.app.servertransaction.LaunchActivityItem.execute(LaunchActivityItem.java:78) 
        at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:108) 
        at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:68) 
        at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1948) 
        at android.os.Handler.dispatchMessage(Handler.java:106) 
        at android.os.Looper.loop(Looper.java:214) 
        at android.app.ActivityThread.main(ActivityThread.java:7050) 
        at java.lang.reflect.Method.invoke(Native Method) 
        at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:494) 
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:965) 

Expected behavior
The app should not crash

Smartphone (please complete the following information):

  • Device: SM-G950F
  • OS: Android 9 on newest patch (April 1 2020)
  • Browser: Brave Browser

Originally posted at GoogleChromeLabs/bubblewrap#143
@tiotdev FYI

Android version support confirmation.

As the demo package, the minsdk is 23 it means that TWA will only support android from 6.0?

As the TWA document, the mindsdk is 16 (from android 4.1) but it also mentioned that only support Chrome version 72 later.
As I know chrome 72 only supports android from 4.4 So could you please confirm what is the minsdk will support TWA?

Thanks.

Installation

I would like to use this package but could you please give these questions to readme?
how to add the package to implemenation as dependencies in gradle file?
and how to call a function launchAsTrustedWebActivity in MainActiviy app?

thanks.

Breakdown on supported features at browsers

android-browser-helper library declares minSdk=16. But it sounds like user experience depends a lot on which browser is being used and theirs version. It's android so not everyone is on single browser - Chrome. And some (most?) browsers including Chrome have stopped supporting sdk16 already.

Currently it is quite hard to understand and estimate how many users are ending up in 'reduced compatible behaviour' bucket. Knowing the audience size would help to better estimate an effort into supporting those users or not.

Is it possible and do you think it is valuable to gather this information at this project (and let people contribute the rest of the browsers if they are interested)? Something like this:

Browser Chrome Custom Tabs Trusted Web Activity Splash Screen
Chrome v45, released 2016, supports sdk 16+ v72, released 2019, supports sdk 19+) v75, released 2019, supports sdk 19+)
Samsung v4, released 2016, supports sdk16? Soon ✖️
Android WebView Same as Chrome for android 21+ but does WebView supports CCT on android below?
Firefox v57, release 2017, supports android sdk 16+ ✖️ ✖️

OK to subclass DelegationService?

I'm evaluating how we might use android-browser-helper in our app. In an ideal world we'd be able to use more notification functionality than the web currently provides, so I started poking around.

I just did a quick test subclassing DelegationService and changing the service in the manifest XML to point to my subclass... and it works! But I wanted to check whether this is something you want people to be doing with the library and something that would be supported down the line?

[Ask] Is pre-render content still supported?

May I know the feature pre-render-content below is still supported in the android browser helper?
if yes, could you please share with us how to implement it?

https://developer.chrome.com/multidevice/android/customtabs#pre-render-content

We have a scenario like that:

  1. Run the TWA app with a specific link
  2. From TWA activity, we use deep-link to open another native activity
  3. From Activity, we do some tasks and depend on results we will return back TWA with new URL
    However when back to TWA with a new URL, there is still delay time which still shows previous page with the old URL before direct TWA to new URL.
    So I would like to know if we can pre-render or some tricks to open new TWA without showing the previous page?

Thank you in advance.

Prepare for package visibility changes on Android 11

Applications targeting sdk level 30 will need to declare their queries in order to be able to read packages from the PackageManager. This impacts applications using Trusted Web Activity, as we need to query for installed browsers to connect to the service or decide on fallback strategies.

Adding a queries section with the appropriate markup android to the library AndroidManifest.xml will also import those queries into application using the library, via Manifest merging.

The following markup should be enough:

<queries>
    <intent>
        <action android:name="android.intent.action.VIEW" />
        <category android:name="android.intent.category.BROWSABLE" />
        <data android:scheme="https" />
    </intent>
</queries>

More information on package visibility changes on: https://developer.android.com/preview/privacy/package-visibility

WebView fallback

Investigate providing a WebView fallback when the device does not have a TWA provider.

  • Have a look at current usage.
  • Consider APK size increase.
  • Consider WebView Web API support.

Requirements for a WebView fallback:

  • Opens startUrl in full-screen
  • Supports multiple Origins
  • Handles external navigations using CustomTabs
  • New Intents should re-use an existing Activity / WebView
  • Handle orientation changes so that page state isn't lost
  • Handle onPause/onResume
  • Handle onBackPressed
  • Handle onSaveInstanceState
  • Enable domstorage, database, etc.
  • Splash screen support
  • Immersive mode
  • Sets android-app://<package-id> referrer.

NullPointerException in com.google.androidbrowserhelper.trusted.TwaLauncher.launchWhenSplashScreenReady

Describe the bug
We have recently upgraded from the google custom tabs client to android browser helper and notice a significant number of crashes, the highest being related to a NullPointerException from com.google.androidbrowserhelper.trusted.TwaLauncher.launchWhenSplashScreenReady

To Reproduce
Steps to reproduce the behavior:

  1. Download Badoo Lite from play store using one of the mentioned devices in screenshot.
  2. Launch the app

Errors are recorded when the app launches, play console has this stack trace from a Motorola Moto C Plus, but see also attached affected devices):

java.lang.NullPointerException: 
  at androidx.browser.trusted.TrustedWebActivityIntentBuilder.build (TrustedWebActivityIntentBuilder.java:220)
  at com.google.androidbrowserhelper.trusted.TwaLauncher.launchWhenSplashScreenReady (TwaLauncher.java:229)
  at com.google.androidbrowserhelper.trusted.TwaLauncher.lambda$launchWhenSessionEstablished$3$TwaLauncher (TwaLauncher.java:217)
  at com.google.androidbrowserhelper.trusted.-$$Lambda$TwaLauncher$Pgq1RErTrlHE2hqdSd7zUQR6Yz4.run (lambda)
  at com.google.androidbrowserhelper.trusted.splashscreens.PwaWrapperSplashScreenStrategy.onSplashImageTransferred (PwaWrapperSplashScreenStrategy.java:202)
  at com.google.androidbrowserhelper.trusted.splashscreens.PwaWrapperSplashScreenStrategy.lambda$configureTwaBuilder$0$PwaWrapperSplashScreenStrategy (PwaWrapperSplashScreenStrategy.java:195)
  at com.google.androidbrowserhelper.trusted.splashscreens.-$$Lambda$PwaWrapperSplashScreenStrategy$w9o5iqMEy62ZZ2i_sMAmRiQ7IGw.onFinished (lambda)
  at com.google.androidbrowserhelper.trusted.splashscreens.SplashImageTransferTask$1.onPostExecute (SplashImageTransferTask.java:144)
  at com.google.androidbrowserhelper.trusted.splashscreens.SplashImageTransferTask$1.onPostExecute (SplashImageTransferTask.java:91)
  at android.os.AsyncTask.finish (AsyncTask.java:660)
  at android.os.AsyncTask.-wrap1 (AsyncTask.java)
  at android.os.AsyncTask$InternalHandler.handleMessage (AsyncTask.java:677)
  at android.os.Handler.dispatchMessage (Handler.java:110)
  at android.os.Looper.loop (Looper.java:203)
  at android.app.ActivityThread.main (ActivityThread.java:6251)
  at java.lang.reflect.Method.invoke (Native Method)
  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run (ZygoteInit.java:1075)
  at com.android.internal.os.ZygoteInit.main (ZygoteInit.java:936)

Expected behavior
App launches without the NullPointerException

Did this ever used to work
Similar error happened with google tabs client.

Screenshots
Screenshot 2020-06-08 at 12 56 24
Screenshot 2020-06-08 at 13 04 36

Code Snippets
Splash screen strategy is being set with this code:

this.mSplashScreenStrategy = new PwaWrapperSplashScreenStrategy(this, this.mMetadata.splashImageDrawableId, this.getColorCompat(this.mMetadata.splashScreenBackgroundColorId), this.getSplashImageScaleType(), this.getSplashImageTransformationMatrix(), this.mMetadata.splashScreenFadeOutDurationMillis, this.mMetadata.fileProviderAuthority);

These all have values except for transformation matrix which is null.

Smartphone (please complete the following information):

  • Device: Motorola Moto C Plus
  • OS: Android 8.1
  • Browsers Installed: Chrome
  • Browser Versions: Don't know
  • android-browser-helper library version: 1.1.0

Additional context
Badoo Lite is released on the play store for low end devices as an alternative for the native android app.

​dependencies​ {     ​//​...​     implementation ​'​com.google.androidbrowserhelper:androidbrowserhelper:1.1.0​'​ }

Read this First
If you have a Trusted Web Activity related question, the best place to ask it is on StackOverflow, on the
trusted-web-activity tag, which is also monitored by the team.

Is your feature request related to a problem? Please describe.
A clear and concise description of what the problem is. Ex. It would be really cool if [...]

Describe the solution you'd like
A clear and concise description of what you want to happen.

Describe alternatives you've considered
A clear and concise description of any alternative solutions or features you've considered.

Additional context
Add any other context or screenshots about the feature request here.

Hiding NavBar and StatusBar

It seems like NavBar and StatusBar can only change color with the existing functionality, while the installed PWA app is able to be truly full-screen. Am I missing something or is it a bug?

Enable appending extra parameters to a deep link query string

Developers frequently use an extra query parameter like &twa=1 to segment web traffic coming from the Trusted Web Activity implementation. LauncherActivity handles deep links correctly, but doesn't allow configuring appending the extra parameter without developers creating their own LauncherActivity.

Ideally, we would allow developers to configure extra parameters via the AndroidManifest. This would allow developers to add extra parameters without having to write Java code and allow llama-pack to help developers to configure it.

forceFallbackStrategy

[google translate]
Not enough forceFallbackStrategy

For example, if the application is running on the Android TV platform and some browser is installed on it, then pwa is currently running in this browser, and I want getFallbackStrategy to be executed for the Android TV platform and run in webview.

To do this, I have to copy all the code from LauncherActivity and do a check at the beginning
getPackageManager().hasSystemFeature(PackageManager.FEATURE_LEANBACK)

[orig_ru]
Не хватает forceFallbackStrategy

Например, если приложение запущено на платформе андроид тв, и на нем установлен какой то браузер, то в данный момент pwa запускается в этом браузере, а я хочу чтоб в любом случае для платформы андроид тв выполнилось getFallbackStrategy и запустился во webview.

Для этого мне приходится копировать весь код из LauncherActivity и в начале делать проверку
getPackageManager().hasSystemFeature(PackageManager.FEATURE_LEANBACK)

Cannot make multi domain part to work

App in testing - https://play.google.com/apps/testing/ru.rambler.news
Starting domain - https://www.rambler.ru, additional domains are https://news.rambler.ru, https://sport.rambler.ru, etc (8 additional domains in total).
Done exactly as described in multi-domain demo (and readme), every domain has /.well-known/assetlinks.json exactly the same as starting domain. All required parts in strings.xml, AndroidManifest and build file are also done but still...
Starting domain verifies OK while all additional domains show blue url bar and act as unverified origins when user passes to them via the link on a starting page.

  • Signing config matches sha256 in assetlinks.
  • Build in Android Studio 3.5
  • Last test performed with Chrome 80.0.3987.87 (still fail)

Files included in following archive:
app_files.zip

asset_statements delegation permisson

Looking at README, in order to enable multiple domains, we need to add the "asset_statements" as declared there:

  <string name="asset_statements">
    [{
        \"relation\": [\"delegate_permission/common.share_location\"],
        \"target\": {
            \"namespace\": \"web\",
            \"site\": \"https://github.com\"
        }
    }],
    [{
        \"relation\": [\"delegate_permission/common.share_location\"],
        \"target\": {
            \"namespace\": \"web\",
            \"site\": \"https://www.google.com\"
        }
    }],
    [{
        \"relation\": [\"delegate_permission/common.share_location\"],
        \"target\": {
            \"namespace\": \"web\",
            \"site\": \"https://www.wikipedia.com\"
        }
    }],
    </string>

But looking at source code, the delagate_permission is differente than is wrote in README.

https://github.com/GoogleChrome/android-browser-helper/blob/master/demos/twa-multi-domain/src/main/res/values/strings.xml

  <string name="asset_statements">
    [{
        \"relation\": [\"delegate_permission/common.handle_all_urls\"],
        \"target\": {
            \"namespace\": \"web\",
            \"site\": \"https://github.com\"
        }
    }],
    [{
        \"relation\": [\"delegate_permission/common.handle_all_urls\"],
        \"target\": {
            \"namespace\": \"web\",
            \"site\": \"https://www.google.com\"
        }
    }],
    [{
        \"relation\": [\"delegate_permission/common.handle_all_urls\"],
        \"target\": {
            \"namespace\": \"web\",
            \"site\": \"https://www.wikipedia.com\"
        }
    }],
    </string>

The first one is using delegate_permission/common.share_location and the second one is using delegate_permission/common.handle_all_urls.

Questions:

  1. Which one is the correct?
  2. Does it matter to enable multi domains?

Update Library to use android.browser-1.2.0

The version of the androidx.browser that android-browser-helper depends has reached stable, with some minor API changes.

We need to update android-browser-helper with those changes, as a path for version 1.0.

Library crashes when used with androidx.browser latest version

This library crashes when used with androidx.browser latest version (as of today, v1.2.0-alpha09).

Steps to reproduce

  1. Configure the app/build.gradle with the latest versions of both androidx.browser and android-browser-helper:
api 'androidx.browser:browser:1.2.0-alpha09'
implementation 'com.google.androidbrowserhelper:androidbrowserhelper:0.1.0-alpha1'
  1. Launch a Chrome Custom Tab like in the demo example:
TrustedWebActivityIntentBuilder builder = new TrustedWebActivityIntentBuilder(Uri.parse("https://www.google.com"))
	.setNavigationBarColor(Color.RED)
	.setToolbarColor(Color.RED);

new TwaLauncher(this).launch(builder, null, null);

Expected result

The tab should open without any error. This is the case if we use androidx.browser version 1.2.0-alpha08.

Actual result

An exception is thrown. Stack trace:

java.lang.NoSuchMethodError: No virtual method getUrl()Landroid/net/Uri; in class Landroidx/browser/trusted/TrustedWebActivityIntentBuilder; or its super classes (declaration of 'androidx.browser.trusted.TrustedWebActivityIntentBuilder' appears in /data/app/org.example.customtabsdemo-1/base.apk)
        at com.google.androidbrowserhelper.trusted.TwaLauncher.launchCct(TwaLauncher.java:139)
        at com.google.androidbrowserhelper.trusted.TwaLauncher.launch(TwaLauncher.java:127)
        at org.example.customtabsdemo.android.ui.AppListActivity.showWebBrowser(AppListActivity.java:193)
        at org.example.customtabsdemo.android.ui.AppListActivity.openApplication(AppListActivity.java:171)
        at org.example.customtabsdemo.android.ui.AppListActivity.access$600(AppListActivity.java:40)
        at org.example.customtabsdemo.android.ui.AppListActivity$1.onRowClicked(AppListActivity.java:116)
        at org.example.customtabsdemo.android.ui.adapters.AppDescriptorAdapter.lambda$onBindViewHolder$1$AppDescriptorAdapter(AppDescriptorAdapter.java:92)
        at org.example.customtabsdemo.android.ui.adapters.-$$Lambda$AppDescriptorAdapter$lOIWUz164uqu7oQSxw09vNIC5-8.onClick(lambda)
        at android.view.View.performClick(View.java:5246)
        at android.view.View$PerformClick.run(View.java:21256)
        at android.os.Handler.handleCallback(Handler.java:739)
        at android.os.Handler.dispatchMessage(Handler.java:95)
        at android.os.Looper.loop(Looper.java:145)
        at android.app.ActivityThread.main(ActivityThread.java:6914)
        at java.lang.reflect.Method.invoke(Native Method)
        at java.lang.reflect.Method.invoke(Method.java:372)
        at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1404)
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1199)

Proposed fix

TwaLauncher should be modified so that it no longer calls TrustedWebActivityIntentBuilder.getUrl(). That method no longer exists. It was removed in androidx.browser v1.2.0-alpha09.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.