簡體   English   中英

從可信網絡活動 (TWA) 啟動另一個活動

[英]Launching another activity from a Trusted Web Activity (TWA)

我在嘗試通過意圖 URI 從 TWA 啟動另一個活動時遇到問題。 "intent://#Intent;scheme=subscriptionschemetwa;package=com.package.www.twa;end" ,包名在現實中是唯一的。

我玩過它們,在 URI 中添加了主機、動作、附加功能等,但沒有任何效果。

由於我是本機開發的新手,我希望得到一些幫助。 該應用程序本身尚未在 Google Play 上公開提供(僅限內部使用),它使用 Bubblewrap 進行簽名和打包,並通過 adb 安裝。 Intent URI 的回退確實有效,因為它將我帶到 Store 的內部列表,但我不知道為什么沒有啟動該活動。

XML 塊:

        <activity android:name="SubscriptionActivity">
            <intent-filter>
                <data
                    android:host="com.package.www.twa"
                    android:scheme="subscriptionschemetwa" />
                <action android:name="android.intent.action.VIEW" />
                <category android:name="android.intent.category.DEFAULT" />
                <category android:name="android.intent.category.BROWSABLE" />
            </intent-filter>
        </activity>

Activity 與批量創建相同,添加了一個日志來檢查它是否曾經進入該方法。 它不是。

class SubscriptionActivity : AppCompatActivity() {
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        println("------test------")
        setContentView(R.layout.activity_subscription)
    }
}

單擊指向意圖 URI 的鏈接后的 logcat 日志似乎顯示根本沒有嘗試啟動活動,而是直接進入商店。 我可以直接通過 adb shell 運行活動就好了。

09-11 20:57:30.419  1595 25814 I CLP     : startActivity sender check.  com.android.chrome to Intent { act=android.intent.action.VIEW cat=[android.intent.category.BROWSABLE] dat=market://details?id=com.package.www.twa&referrer=com.android.chrome flg=0x10000000 pkg=com.android.vending cmp=com.android.vending/com.google.android.finsky.activities.MarketDeepLinkHandlerActivity (has extras) }
09-11 20:57:30.607  9562  9804 I AppIconSolution: load=com.package.www.twa, bg=96-96, dr=132-132, forDefault=false, density=0
09-11 20:57:30.611  9562  9804 I AppIconSolution: load=com.package.www.twa-theme2, bg=96-96, dr=132-132, tarScale=0.65, relScale=0.48, mask=false
09-11 20:57:30.786 22165 22165 I Finsky  : [2] hze.a(11): Selecting account [xxxxxxxxxxxxxxxxxxxxxxxxxx] for package com.package.www.twa. overriding=[true]
09-11 20:57:30.794 22165 22165 I Finsky  : [2] hze.a(11): Selecting account [xxxxxxxxxxxxxxxxxxxxxxxxxx] for package com.package.www.twa. overriding=[true]
09-11 20:57:30.917 22165 22200 I Finsky  : [842] lge.run(418): Dropped referrer for com.package.www.twa because dropped_already_installed
09-11 20:57:30.934 22165 22165 I Finsky  : [2] hze.a(11): Selecting account [xxxxxxxxxxxxxxxxxxxxxxxxxx] for package com.package.www.twa. overriding=[true]
09-11 20:57:30.940 22165 22165 I Finsky  : [2] hze.a(11): Selecting account [xxxxxxxxxxxxxxxxxxxxxxxxxx] for package com.package.www.twa. overriding=[true]

任何輸入都值得贊賞,我已經在這個問題上呆了好幾天了,我只是無法理解它。

因此,意圖 URI 似乎是錯誤的。 我實際上設法使用我認為已棄用的通過意圖 URI 調用活動的方式來毫無問題地啟動活動。 但是,嘿,它有效。 我最終使用的 URI 是:

subscriptionschemetwa://www.package.com

或更籠統地說

scheme://host

希望它可以幫助人們避免像我一樣浪費時間:D

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM