URL 栏未隐藏

Posted

技术标签:

【中文标题】URL 栏未隐藏【英文标题】:URL Bar is not Hiding 【发布时间】:2019-08-16 12:39:36 【问题描述】:

我们正在开发 PWA 应用程序以将其提交到 Play 商店。我们使用 TWA,遵循所有概念,但不知何故我们无法隐藏 URL BAR。

数字资产链接已配置和测试。我们已经用 TWA 连接了网站,我们已经成功测试了映射编辑器,我们添加了意图过滤器,成功测试了与 assetslinks.json 的关联

android 清单

<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    package="eu.clubforceone.mobile">

    <application
        android:allowBackup="true"
        android:icon="@mipmap/ic_launcher"
        android:label="@string/appName"
        android:supportsRtl="true"
        android:theme="@style/Theme.LauncherActivity">

        <meta-data
            android:name="asset_statements"
            android:resource="@string/assetStatements" />

        <activity
            android:name="android.support.customtabs.trusted.LauncherActivity"
            android:label="@string/appName">
            <tools:validation testUrl="https://login.clubforce.eu" />

            <meta-data
                android:name="android.support.customtabs.trusted.DEFAULT_URL"
                android:value="@string/launchUrl" />

            <meta-data
                android:name="android.support.customtabs.trusted.STATUS_BAR_COLOR"
                android:resource="@color/colorPrimary" />

            <meta-data
                android:name="android.support.customtabs.trusted.SPLASH_IMAGE_DRAWABLE"
                android:resource="@drawable/splash" />

            <meta-data
                android:name="android.support.customtabs.trusted.SPLASH_SCREEN_BACKGROUND_COLOR"
                android:resource="@color/whiteColor" />

            <meta-data
                android:name="android.support.customtabs.trusted.SPLASH_SCREEN_FADE_OUT_DURATION"
                android:value="300" />

            <meta-data
                android:name="android.support.customtabs.trusted.FILE_PROVIDER_AUTHORITY"
                android:value="@string/providerAuthority" />

            <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="login.clubforce.eu" />
            </intent-filter>
        </activity>

        <provider
            android:name="android.support.v4.content.FileProvider"
            android:authorities="@string/providerAuthority"
            android:grantUriPermissions="true"
            android:exported="false">
            <meta-data
                android:name="android.support.FILE_PROVIDER_PATHS"
                android:resource="@xml/filepaths" />
        </provider>

        <service
            android:name="android.support.customtabs.trusted.TrustedWebActivityService"
            android:enabled="@bool/enableNotification"
            android:exported="@bool/enableNotification">

            <intent-filter>
                <action android:name="android.support.customtabs.trusted.TRUSTED_WEB_ACTIVITY_SERVICE" />
                <category android:name="android.intent.category.DEFAULT" />
            </intent-filter>
        </service>

    </application>
</manifest>

build.gradle 模块应用程序

apply plugin: 'com.android.application'

def twaManifest = [
        applicationId: 'eu.clubforceone.mobile',
        hostName: 'login.clubforce.eu', // The domain being opened in the TWA.
        launchUrl: '/', // The start path for the TWA. Must be relative to the domain.
        name: 'Clubforce', // The name shown on the Android Launcher.
        themeColor: '#283795', // The color used for the status bar.
        backgroundColor: '#F6F6F6', // The color used for the splash screen background.
        whiteColor: '#FFFFFF', // The color used for the splash screen background.
        enableNotifications: false // Set to true to enable notification delegation
]

android 
    compileSdkVersion 28
    defaultConfig 
        applicationId "eu.clubforceone.mobile"
        minSdkVersion 16
        targetSdkVersion 28
        versionCode 20003
        versionName '2.2'
        testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"

        // The name for the application on the Android Launcher
        resValue "string", "appName", twaManifest.name

        // The URL that will be used when launching the TWA from the Android Launcher
        resValue "string", "launchUrl", "https://" + twaManifest.hostName + twaManifest.launchUrl

        // The hostname is used when building the intent-filter, so the TWA is able to
        // handle Intents to open https://svgomg.firebaseapp.com.
        resValue "string", "hostName", twaManifest.hostName

        // This variable below expresses the relationship between the app and the site,
        // as documented in the TWA documentation at
        // https://developers.google.com/web/updates/2017/10/using-twa#set_up_digital_asset_links_in_an_android_app
        // and is injected into the AndroidManifest.xml
        resValue "string", "assetStatements",
                '[ \\"relation\\": [\\"delegate_permission/common.handle_all_urls\\"],' +
                        '\\"target\\": \\"namespace\\": \\"web\\", \\"site\\": \\"https://' +
                        twaManifest.hostName + '\\"]'

        // This attribute sets the status bar color for the TWA. It can be either set here or in
        // `res/values/colors.xml`. Setting in both places is an error and the app will not
        // compile. If not set, the status bar color defaults to #FFFFFF - white.
        resValue "color", "colorPrimary", twaManifest.themeColor

        // Sets the color for the background used for the splash screen when launching the
        // Trusted Web Activity.
        resValue "color", "backgroundColor", twaManifest.backgroundColor

        // used only for specific situation where white color is needed
        resValue "color", "whiteColor", twaManifest.whiteColor


        // Defines a provider authority fot the Splash Screen
        resValue "string", "providerAuthority", twaManifest.applicationId + '.fileprovider'

        // The enableNotification resource is used to enable or disable the
        // TrustedWebActivityService, by changing the android:enabled and android:exported
        // attributes
        resValue "bool", "enableNotification", twaManifest.enableNotifications.toString()
    
    buildTypes 
        release 
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        
    
    compileOptions 
        sourceCompatibility JavaVersion.VERSION_1_8
        targetCompatibility JavaVersion.VERSION_1_8
    
    productFlavors 
    


dependencies 
    implementation fileTree(include: ['*.jar'], dir: 'libs')
    implementation 'com.github.GoogleChrome.custom-tabs-client:customtabs:91b4a1270b511ce70245d3440e6267762c5f1c6b'

assetLinks.json

[
  "relation": ["delegate_permission/common.handle_all_urls"],
  "target": 
    "namespace": "android_app",
    "package_name": "eu.clubforceone.mobile",
    "sha256_cert_fingerprints":
    ["CD:D5:D1:54:AC:8F:17:0B:8A:E6:5D:0F:C2:07:1D:FC:D7:2C:16:EE:66:A4:D9:F6:DA:1C:57:12:1B:57:A5:F9"]
  
]

我只是不知道该怎么办......

这是我运行“keytool -list -printcert -jarfile app-release.apk”的结果

Signer #1:

Signature:

Owner: deleted for privacy reason
Issuer: deleted for privacy reason
Serial number: 6beb859e
Valid from: Sun Apr 01 14:33:45 CEST 2018 until: Thu Aug 17 14:33:45 CEST 2045
Certificate fingerprints:
     MD5:  29:FC:96:6C:FC:D0:E4:69:BC:BC:B1:95:01:DA:6D:2D
     SHA1: 00:7E:76:27:F9:5E:51:83:6A:77:70:57:90:A1:B7:56:66:66:A3:99
     SHA256: CD:D5:D1:54:AC:8F:17:0B:8A:E6:5D:0F:C2:07:1D:FC:D7:2C:16:EE:66:A4:D9:F6:DA:1C:57:12:1B:57:A5:F9
     Signature algorithm name: SHA256withRSA
     Version: 3

Extensions: 

#1: ObjectId: 2.5.29.14 Criticality=false
SubjectKeyIdentifier [
KeyIdentifier [
0000: 06 A2 63 AE E8 BD 9A 56   00 66 4E 8B 9C 09 EA 13  ..c....V.fN.....
0010: 20 C8 E5 4E                                         ..N
]
]

【问题讨论】:

【参考方案1】:

您可以使用 PWA2APK 来简化该过程: PWA2APK

【讨论】:

加里你知道吗***.com/questions/65092260/…【参考方案2】:

“assetlinks.json”文件中的“package_name”字段需要指向应用程序包名(与applicationId相同)。

assetlinks.json 文件应如下所示:

[
  "relation": ["delegate_permission/common.handle_all_urls"],
  "target": 
    "namespace": "android_app",
    "package_name": "eu.clubforceone.mobile",
    "sha256_cert_fingerprints":
    ["CD:D5:D1:54:AC:8F:17:0B:8A:E6:5D:0F:C2:07:1D:FC:D7:2C:16:EE:66:A4:D9:F6:DA:1C:57:12:1B:57:A5:F9"]
  
]

【讨论】:

谢谢和抱歉。这是我的错字,包名配置正确,我已经编辑了我的帖子 我看到你也更新了login.clubforce.eu/.well-known/assetlinks.json。您可以强制关闭 Chrome 并重新打开 TWA 吗?您能否为您的 APK 运行以下命令并发布结果:`keytool -list -printcert -jarfile app.apk`` 几个后续问题:我注意到初始 URL 是 login.clubforce.eu。用户登录后域是否会更改?如果是这种情况,您还需要验证其他域。 不。首字母是 login.clubforce.eu。如果没有 cookie,则用户将被重定向到 login.clubforce.eu/login。如果用户登录,那么他将获得位于 login.clubforce.eu 上的主页视图。只有与其他域的连接是一些 javascript 资产,例如 jquery cdn。 明白了。配置看起来不错,但我可能遗漏了一些东西。你能分享 APK 吗?【参考方案3】:

如果您让 Play 商店管理您的签名,请检查您的 assetslinks.json 是否包含来自您的 Play 商店设置的 SHA215,而不是由 keytool 生成的。如other answer 中所述。

也就是说,我的情况和你一样。我也无法从我的 TWA 应用程序中删除 URL 栏。

【讨论】:

我很乐意查看 APK 并帮助找出问题所在。 感谢@andreban 的好意。我已将 APK 放在这里:thelocal.com/app/release.apk,您可以直接通过 tech@thelocal.com 与我联系。 更新到上面:我的assetlinks.json中有一个错误,指纹错误地包含了“SHA-256:”前缀。我删除了它,现在我们的应用程序可以在不显示 URL 栏的情况下运行。

以上是关于URL 栏未隐藏的主要内容,如果未能解决你的问题,请参考以下文章

iPhone/iOS 状态栏未隐藏在 Xcode 项目中

iOS8 Xcode 6 Cordova 状态栏未正确隐藏

确定移动设备的最大浏览器高度(地址栏未显示时)

SWRevealViewController 隐藏我的前视图控制器的导航栏

在 URL 中隐藏锚标记 [参考:Rails 在 URL 中隐藏 #anchor 标记]

隐藏表单域URL重写cookiesession