How to pass data through deep linking?

让人想犯罪 __ 提交于 2019-12-04 23:50:43

问题


I am having a list of offers in my application and there is a share button on every list item.I am using deep link to open a offer detail activity of my application when any user clicks on the shared link.i am in a situation that my detail page activity is being triggered when someone clicks the link ,But how can i know ,which offer detail activity to show when some one clicks on the shared deep link .


回答1:


The manifest file will remain same as specified in this link https://developer.android.com/training/app-indexing/deep-linking.html

But you can provide the extra data in the link you send to the user as www.example.com/gizmos?key=valueToSend

then in the activity you can do something like

Uri data = intent.getData();

data.getQueryParameter("key");



回答2:


Supposing that you generate a separate share link for each item. You could send some parameters along with the deep link URL and then receive them in the App. Any kind of an ID would suffice. (Source: this)

<intent-filter android:label="@string/filter_title_viewgizmos">
    <action android:name="android.intent.action.VIEW" />
    <category android:name="android.intent.category.DEFAULT" />
    <category android:name="android.intent.category.BROWSABLE" />
    <!-- Accepts URIs that begin with "http://www.example.com/gizmos” -->
    <data android:scheme="http"
          android:host="www.example.com"
          android:pathPrefix="/gizmos" />
    <!-- note that the leading "/" is required for pathPrefix-->
    <!-- Accepts URIs that begin with "example://gizmos”
    <data android:scheme="example"
          android:host="gizmos" />
    -->
</intent-filter>

Taking up this example, if the app deep links here, you can receive your intent in the corresponding activity (Here: com.example.android.GizmosActivity) and extract information from there itself.



来源:https://stackoverflow.com/questions/31889744/how-to-pass-data-through-deep-linking

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!