【问题标题】:How to open a fragment through android deep link from mail?如何通过邮件中的android深层链接打开片段?
【发布时间】:2021-11-14 20:38:03
【问题描述】:

我需要在我的应用程序中打开一个特定的片段,点击电子邮件应用程序中的确认链接。有没有可能,如果有,我可以从这个链接收到信息吗?

【问题讨论】:

标签: android kotlin email android-fragments deep-linking


【解决方案1】:

首先,您需要在清单中将这些代码添加到<activity/>(For more information):

<activity
        android:name=".MainActivity"
        android:exported="true"
        android:launchMode="singleTask">
        <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="@string/APP_LINKS_URL"
                android:scheme="http" />
        </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="@string/APP_LINKS_URL"
                android:scheme="https" />
        </intent-filter>
    </activity>

@string/APP_LINKS_URL 是 url 地址,如 some.address.com (For more info)

之后,通过单击链接,您的活动会以意图对象中的此链接(如 Uri:intent.data)开始。基于此链接,您可以打开或导航到应用程序中的任何片段。对于屏幕之间的导航,您可以使用导航组件navigation-deep-link.

override fun onCreate(savedInstanceState: Bundle?) {
    super.onCreate(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 specify fragment
    }
}

你可以从这个链接(Uri)获取信息:intent.data

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2016-06-26
    • 1970-01-01
    • 1970-01-01
    • 2019-04-15
    • 1970-01-01
    • 2017-04-29
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多