2015-08-08 57 views
3

我在我的应用程序中有优惠的列表,并且每个列表项目上都有一个共享按钮。当任何用户点击共享链接时,我正在使用深层链接打开我的应用程序的优惠活动细节。当有人点击链接时我的详细信息页面活动正在被触发,但是我怎么知道,哪些信息提供了当某个人点击共享深层链接时显示的详细活动。如何通过深层链接传递数据?

+1

您可以阅读发起该活动的意图的数据,获得基于特定的URL报价信息,然后用它来显示正确的活动。有关阅读启动意向的更多详细信息,请访问:https://developer.android.com/training/app-indexing/deep-linking.html#handling-intents – subeeshb

回答

2

假设您为每个项目生成单独的共享链接。您可以发送一些参数以及深层链接网址,然后在应用程序中接收它们。任何类型的ID都足够了。 (来源: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> 

背起这个例子中,如果在这里应用深层链接,您可以在相应的活动(在这里:com.example.android.GizmosActivity)收到你的意图,并从那里提取信息本身。