我有用於打開手機瀏覽器,用戶會被重定向到我的web應用程序,當某一用戶動作之後,webapp的使用意圖過濾自動關閉Chrome自定義標籤
重定向到應用程序的應用程序<application>
<activity
android:name="com.xyz.sdk.SomeActivity"
android:allowTaskReparenting="true"
android:configChanges="keyboardHidden|orientation|keyboard|screenSize"
android:launchMode="singleTask"
android:noHistory="true"
android:theme="@android:style/Theme.NoTitleBar">
<intent-filter>
<data android:scheme="someString-${applicationId}" />
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />
</intent-filter>
</activity>
</application>
最近我遷移到使用Chrome自定義選項卡,而不是瀏覽器(Webview是不是一種選擇,出於安全考慮)
不幸的是,在鍍鉻自定義選項卡重新導向到應用程序時,鉻自定義選項卡不會自動關閉。儘管我可以通過日誌驗證應用程序已收到響應,但自定義選項卡保持打開狀態並保持最佳狀態,因此用戶無法查看應用程序上發生的情況,直到他關閉應用程序。
我發現的一種解決方法是在啓動我的自定義選項卡時設置NEW_TASK標誌,但這使得我的應用程序和自定義選項卡顯示爲兩個單獨的應用程序,這是我從第一個瀏覽器移開的全部原因地點。總結:我有應用程序A,它打開一個自定義選項卡,在自定義選項卡中打開的web應用程序使用意圖過濾器重定向迴應用程序A,但vustom選項卡不會關閉並保持最前狀態,直到用戶手冊關閉它。
我已經嘗試爲自定義選項卡意圖設置NO_HISTORY標誌,但它沒有區別。
自定義標籤代碼:
CustomTabsIntent customTabsIntent = new CustomTabsIntent.Builder()
.setShowTitle(true)
.setToolbarColor(getToolBarColor())
.setStartAnimations(this, android.R.anim.slide_in_left, android.R.anim.slide_out_right)
.setExitAnimations(this, android.R.anim.slide_in_left, android.R.anim.slide_out_right)
.build();
customTabsIntent.intent.setFlags(Intent.FLAG_ACTIVITY_NO_HISTORY);
customTabsIntent.launchUrl(this, Uri.parse(url));
customTabsIntent.launchUrl(this, Uri.parse(url));
UPDATE 我已經意識到,如果意圖過濾器重定向到一個不同的應用程序,然後自定義選項卡成功地關閉(提供了一個singletop活動,沒有歷史設置爲true) 但在我的情況下,我們需要重定向回到自定義選項卡被調用的同一個活動。
沒有遺憾的工作:\ –
我所做的清單變了樣你的建議,仍然沒有效果 –
我能得到這個由「singleTop」改變啓動模式設置爲「singleTask」或「工作singleInstance」。在這種模式下,重定向將通過'onNewIntent'來到相同的Activity。 – bkant