![](/img/trans.png)
[英]Open deep link url when clicking on FCB notification for both iOS and Android
[英]Android deep link delivered again when I reopen the app
我在我的應用程序中使用 深層鏈接。
這是我的清單活動
<activity
android:name=".ui.MainActivity"
android:exported="true"
android:launchMode="singleTask"
android:screenOrientation="portrait"
android:theme="@style/AppTheme.NoActionBar.Launcher">
<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:host="app.mydomain.com"
android:pathPrefix="/prefix"
android:scheme="https" />
</intent-filter>
</activity>
這就是我獲得深層鏈接的方式
Uri uri = getIntent().getData();
在我處理完MainActivity
中的深度鏈接和一些其他邏輯后,我將用戶導航到其他活動,並完成MainActivity
。
問題是,在某些情況下,我一遍又一遍地獲得深層鏈接。 這是發生問題的場景:
在我點擊鏈接的那一刻,我的應用程序不在 memory 中,也沒有通過點擊系統后退按鈕關閉。
在我的應用程序中處理鏈接后,我使用系統后退按鈕關閉應用程序。
然后我通過單擊菜單中的預覽(不是啟動器圖標)打開應用程序,其中包含所有 memory 應用程序(通過單擊手機上的一個系統按鈕打開)。 並再次傳送深層鏈接。
問題是,當鏈接交付時我無法確定,這是這個特殊的問題案例場景,我應該忽略鏈接,還是用戶實際點擊了鏈接,我應該處理它。
將鏈接保存在 static 變量中以檢查是否是相同的鏈接是不好的,因為用戶可能會再次單擊相同的鏈接以查看相同的數據。
Firebase 動態鏈接也存在此問題。
我的手機在 Android 12(api 級別 31)、Samsung S21 上運行
找到了解決方案,感謝這個答案
我使用此方法檢查活動是否從歷史記錄啟動,如果為真,則忽略深層鏈接
private boolean isActivityLaunchedFromHistory() {
return getIntent().getFlags() ==
(Intent.FLAG_ACTIVITY_NEW_TASK
| Intent.FLAG_ACTIVITY_LAUNCHED_FROM_HISTORY);
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.