我需要在我的應用程式中打開指定的片段,在點擊電子郵件應用程式中的確認鏈接后。這可能嗎?如果可能,我可以從這個鏈接中獲得資訊嗎?
uj5u.com熱心網友回復:
首先你需要在你的清單中添加這些代碼到<activity/>(For more information):
<activity
android:name=".MainActivity"/span>
android:exported="true"。
android:launchMode="singleTask">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<類別 android:name="android.intent.category.LAUNCHER" />
</intent-filter>
<intent-filter android:autoVerify="true">
<action android:name="android.intent.action.VIEW" />
<類別 android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />
<data
android:host="@string/APP_LINKS_URL"/span>
android:scheme="http" />
</intent-filter>
<intent-filter android:autoVerify="true">
<action android:name="android.intent.action.VIEW" />
<類別 android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />
<data
android:host="@string/APP_LINKS_URL"/span>
android:scheme="https" />
</intent-filter>
</activity>
@string/APP_LINKS_URL是url地址,如some.address.com(For more information)
之后,通過點擊一個鏈接,你的活動開始于intent物件中的這個鏈接(如Uri:intent.data)。基于這個鏈接,你可以打開或導航到你的應用程式中的任何片段。對于螢屏之間的導航,你可以使用導航組件navigation-deep-link.
override fun onCreate(servedInstanceState: Bundle? ){
super.onCreate(s savedInstanceState)
_binding = ActivityMainBinding.inflate(layoutInflater)
setContentView(binding.root)
//...。
if (intent.data?.toString()?.contains(getString(R.string.APP_LINKS_URL)) == true) {
//your logic to navigate to specified fragment。
}
}
而且你可以從這個鏈接(Uri)獲得資訊。intent.data
轉載請註明出處,本文鏈接:https://www.uj5u.com/qukuanlian/330157.html
標籤:
