无法在 Android 的 TWA/PWA 应用程序中隐藏 URL 栏

Cannot hide URL bar in TWA/PWA app in Android

我正在尝试使用此处的 Google TWA 指南让我的 PWA 应用工作:

https://developers.google.com/web/updates/2019/02/using-twa

我已经多次完全按照指南从头到尾完成,但似乎无法让它在任何时候隐藏 URL 栏。

我已将 apk(发布版)上传到 Google Play 管理中心,并允许它为我签名。

我基本上已经解决了所有关于 SO 的问题,none 的解决方案似乎对我有用,或者我已经正确设置了它们。

我已经尝试和检查过的注意事项:

我的build.gradle(模块)

apply plugin: 'com.android.application'

android {
    compileSdkVersion 29
    buildToolsVersion "29.0.0"
    defaultConfig {
        applicationId "com.mypwadomain.www"
        minSdkVersion 16
        targetSdkVersion 29
        versionCode 3
        versionName "0.1.9"
        testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
        }
    }
    compileOptions {
        sourceCompatibility JavaVersion.VERSION_1_8
        targetCompatibility JavaVersion.VERSION_1_8
    }
}

dependencies {
    implementation fileTree(dir: 'libs', include: ['*.jar'])
    implementation 'androidx.appcompat:appcompat:1.0.2'
    implementation 'com.github.GoogleChrome.custom-tabs-client:customtabs:d08e93fce3'
    testImplementation 'junit:junit:4.12'
    androidTestImplementation 'androidx.test:runner:1.2.0'
    androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0'
}

我的AndroidManifest.xml

<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    package="com.mypwadomain.www">

    <application
        android:allowBackup="true"
        android:icon="@mipmap/ic_launcher"
        android:label="PWAAppName"
        android:roundIcon="@mipmap/ic_launcher_round"
        android:supportsRtl="true"
        android:theme="@style/AppTheme"
        tools:ignore="GoogleAppIndexingWarning">
        <meta-data
            android:name="asset_statements"
            android:resource="@string/asset_statements" />
        <activity
            android:name="android.support.customtabs.trusted.LauncherActivity">

            <meta-data
                android:name="android.support.customtabs.trusted.DEFAULT_URL"
                android:value="https://www.mypwadomain.com/login" />

            <intent-filter>
                <action android:name="android.intent.action.MAIN" />
                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>

            <intent-filter android:autoVerify="true">
                <action android:name="android.intent.action.VIEW"/>
                <category android:name="android.intent.category.DEFAULT" />
                <category android:name="android.intent.category.BROWSABLE"/>

                <data
                    android:scheme="https"
                    android:host="www.mypwadomain.com"/>
            </intent-filter>
        </activity>
    </application>
</manifest>

我的strings.xml

<resources>
    <string name="app_name">PWAAppName</string>
    <string name="asset_statements">
        [{
            \"relation\": [\"delegate_permission/common.handle_all_urls\"],
            \"target\": {
                \"namespace\": \"web\",
                \"site\": \"https://www.mypwadomain.com\"}
        }]
    </string>
</resources>

我的assetlinks.json

[{
  "relation": ["delegate_permission/common.handle_all_urls"],
  "target": {
    "namespace": "web",
    "site": "https://www.mypwadomain.com"
  }
},{
  "relation": ["delegate_permission/common.handle_all_urls"],
  "target" : { "namespace": "android_app", "package_name": "com.mypwadomain.www",
    "sha256_cert_fingerprints": ["...Google Signed Fingerprint..."] }
}]

应用本身在 Lighthouse 中的审核作为 100 PWA 兼容性恢复,添加到主屏幕在 Android 和 iOS 设备上运行良好。

我对此很陌生。我主要是 PHP 开发人员,实际应用运行良好。几天前我第一次安装了 Android Studio。从好的方面来说,我使用 PHPStorm,它也是由 JetBrains 制作的,因此这部分有助于缩短学习曲线。

任何关于我可以检查的其他内容的帮助或建议将不胜感激。

编辑: 我通过 android studio 加载了 logcat(我正在处理 Windows)。然后我 运行 处于调试模式的应用程序,结果日志如下。没有 OriginVerifier 或 digital_asset_links

实例
2019-06-20 11:18:12.440 12042-12042/? E/Zygote: accessInfo : 1
2019-06-20 11:18:12.444 12042-12042/? I/SELinux: SELinux: seapp_context_lookup: seinfo=default, level=s0:c94,c257,c512,c768, pkgname=com.mypwaapp.www 
2019-06-20 11:18:12.453 12042-12042/? I/m.mypwaapp.ww: Late-enabling -Xcheck:jni
2019-06-20 11:18:12.609 12042-12042/com.mypwaapp.www W/ActivityThread: Application com.mypwaapp.www is waiting for the debugger on port 8100...
2019-06-20 11:18:12.610 12042-12042/com.mypwaapp.www I/System.out: Sending WAIT chunk
2019-06-20 11:18:13.814 12042-12042/com.mypwaapp.www I/System.out: Debugger has connected
2019-06-20 11:18:13.815 12042-12042/com.mypwaapp.www I/System.out: waiting for debugger to settle...
2019-06-20 11:18:14.017 12042-12042/com.mypwaapp.www I/chatty: uid=10350(com.mypwaapp.www) identical 1 line
2019-06-20 11:18:14.220 12042-12042/com.mypwaapp.www I/System.out: waiting for debugger to settle...
2019-06-20 11:18:14.423 12042-12042/com.mypwaapp.www I/System.out: waiting for debugger to settle...
2019-06-20 11:18:14.625 12042-12042/com.mypwaapp.www I/System.out: waiting for debugger to settle...
2019-06-20 11:18:14.828 12042-12042/com.mypwaapp.www I/System.out: waiting for debugger to settle...
2019-06-20 11:18:15.032 12042-12042/com.mypwaapp.www I/chatty: uid=10350(com.mypwaapp.www) identical 1 line
2019-06-20 11:18:15.235 12042-12042/com.mypwaapp.www I/System.out: waiting for debugger to settle...
2019-06-20 11:18:15.440 12042-12042/com.mypwaapp.www I/System.out: debugger has settled (1500)
2019-06-20 11:18:15.457 12042-12042/com.mypwaapp.www D/ConnectivityManager_URSP: Ursp sIsUrsp=false, sIsCheckUrsp=false, uid=10350
2019-06-20 11:18:15.478 12042-12042/com.mypwaapp.www D/Proxy: urspP is null: 10350
2019-06-20 11:18:15.788 12042-12042/com.mypwaapp.www W/m.mypwaapp.ww: JIT profile information will not be recorded: profile file does not exits.
2019-06-20 11:18:15.831 12042-12042/com.mypwaapp.www I/chatty: uid=10350(com.mypwaapp.www) identical 10 lines
2019-06-20 11:18:15.835 12042-12042/com.mypwaapp.www W/m.mypwaapp.ww: JIT profile information will not be recorded: profile file does not exits.
2019-06-20 11:18:15.948 12042-12042/com.mypwaapp.www I/InstantRun: starting instant run server: is main process
2019-06-20 11:18:16.101 12042-12063/com.mypwaapp.www D/libEGL: loaded /vendor/lib64/egl/libGLES_mali.so
2019-06-20 11:18:16.403 12042-12042/com.mypwaapp.www D/TWAProviderPicker: Found Custom Tabs provider: com.sec.android.app.sbrowser
2019-06-20 11:18:16.404 12042-12042/com.mypwaapp.www D/TWAProviderPicker: Found no TWA providers, using first Custom Tabs provider: com.sec.android.app.sbrowser
2019-06-20 11:18:16.410 12042-12042/com.mypwaapp.www D/TWALauncherActivity: Using URL from Manifest (https://www.mypwaapp.com/login).
2019-06-20 11:18:17.330 12042-12042/com.mypwaapp.www W/m.mypwaapp.ww: Accessing hidden method Landroid/view/View;->computeFitSystemWindows(Landroid/graphics/Rect;Landroid/graphics/Rect;)Z (light greylist, reflection)
2019-06-20 11:18:17.335 12042-12042/com.mypwaapp.www W/m.mypwaapp.ww: Accessing hidden method Landroid/view/ViewGroup;->makeOptionalFitsSystemWindows()V (light greylist, reflection)
2019-06-20 11:18:17.506 12042-12042/com.mypwaapp.www D/OpenGLRenderer: Skia GL Pipeline
2019-06-20 11:18:17.528 12042-12042/com.mypwaapp.www D/EmergencyMode: [EmergencyManager] android createPackageContext successful
2019-06-20 11:18:17.678 12042-12042/com.mypwaapp.www D/InputTransport: Input channel constructed: fd=81
2019-06-20 11:18:17.686 12042-12042/com.mypwaapp.www D/ViewRootImpl@c9324c2[LauncherActivity]: setView = DecorView@fe5f2d3[LauncherActivity] TM=true MM=false
2019-06-20 11:18:17.717 12042-12042/com.mypwaapp.www D/ViewRootImpl@c9324c2[LauncherActivity]: Surface release. android.view.WindowManagerGlobal.setStoppedState:669 android.app.Activity.performStop:7646 android.app.ActivityThread.callActivityOnStop:4352 android.app.ActivityThread.performStopActivityInner:4330 android.app.ActivityThread.handleStopActivity:4405 android.app.servertransaction.StopActivityItem.execute:41 android.app.servertransaction.TransactionExecutor.executeLifecycleState:145 android.app.servertransaction.TransactionExecutor.execute:70 
2019-06-20 11:18:17.779 12042-12042/com.mypwaapp.www D/ViewRootImpl@c9324c2[LauncherActivity]: dispatchAttachedToWindow
2019-06-20 11:18:17.839 12042-12042/com.mypwaapp.www D/ViewRootImpl@c9324c2[LauncherActivity]: Relayout returned: old=[0,0][1440,2960] new=[0,0][1440,2960] result=0x1 surface={valid=false 0} changed=false

编辑 2: 我确实在 logcat 提要中找到了这个:

2019-06-20 12:23:56.772 6226-11769/? I/SingleHostAsyncVerifier: Verification result: checking for a statement with source a: # bpti@709f0232
    w: 29
    , relation delegate_permission/common.handle_all_urls, and target b <
      a: "com.mypwaapp.www"
      b: # bptg@e7d522a2
      w: 118
    >
    w: 120
     --> false.

不确定是否相关。

当我在解决问题时清除 phone (Samsung Note 9) 上的设置时,我的默认浏览器必须重置为三星浏览器。我将默认浏览器设置为 Chrome。一切正常。

感谢安德烈班​​ :)

我遇到了与@Incredibad 类似的情况,我同时安装了 Chrome 和 Chrome Dev,其中 Chrome dev 成为默认浏览器。