如何处理不同活动的应用程序链接?

问题描述:

我有,比如域example.com。它可以与httpshttp一起使用。我有Android客户端用于此服务。我希望客户端能够打开多个链接类型。它们是:如何处理不同活动的应用程序链接?

http://example.com 
https://example.com 
http://example.com/app 
https://example.com/app 

这四个应该在ListActivity上打开。但也有另一个链接,如:

https://testask.com/i/__some_guid__ 
https://testask.com/item/__some_guid__ 
and relevant link without https 

他们应该打开另一个活动,比如说DetailsActivity。目前我有以下意向过滤器为详细活动:

<intent-filter 
    android:autoVerify="true" 
    tools:targetApi="m"> 
    <action android:name="android.intent.action.VIEW" /> 

    <category android:name="android.intent.category.DEFAULT" /> 
    <category android:name="android.intent.category.BROWSABLE" /> 

    <data android:scheme="http" /> 
    <data android:scheme="https" /> 
    <data 
     android:host="@string/root_host_endpoint" 
     android:pathPattern="/i/.*" /> 
    <data 
     android:host="@string/root_host_endpoint" 
     android:pathPattern="/item/.*" /> 
</intent-filter> 

看起来像它的工作正常。但我不明白,如何添加MainActivity意图过滤器指向根主机url并且不重叠DetailsActivity intent过滤器。

韦尔普,一些实验后,我发现下面的意图过滤器工作正常:

 <intent-filter 
      android:autoVerify="true" 
      tools:targetApi="m"> 
      <action android:name="android.intent.action.VIEW" /> 

      <category android:name="android.intent.category.DEFAULT" /> 
      <category android:name="android.intent.category.BROWSABLE" /> 

      <data android:scheme="http" /> 
      <data android:scheme="https" /> 
      <data android:host="@string/root_host_endpoint" /> 
      <data 
       android:host="@string/root_host_endpoint" 
       android:path="/" /> 
      <data 
       android:host="@string/root_host_endpoint" 
       android:path="/app" /> 
     </intent-filter> 

您可以使用不同的意向过滤器进行多项活动。您可以使用Action/Category/Data区分您的意图过滤器。在你的情况下,你必须调整你的数据配置,让它处理不同的意图。所以MainActivity/ListActivity都会有不同的数据结构,而不是DetailsActivity

+0

谢谢你,我的理解,我只是没有得到如何写在XML中。 – Bringoff

<activity android:name=".ListActivity"> 
<intent-filter 
android:autoVerify="true" 
tools:targetApi="m"> 
<action android:name="android.intent.action.VIEW" /> 

<category android:name="android.intent.category.DEFAULT" /> 
<category android:name="android.intent.category.BROWSABLE" /> 

<data android:scheme="http" /> 
<data android:scheme="https" /> 
<data 
    android:host="example.com" 
    android:pathPattern="/*/.*" /> 
</intent-filter> 
</activity> 

<activity android:name=".DetailsActivity"> 
<intent-filter 
android:autoVerify="true" 
tools:targetApi="m"> 
<action android:name="android.intent.action.VIEW" /> 

<category android:name="android.intent.category.DEFAULT" /> 
<category android:name="android.intent.category.BROWSABLE" /> 

<data android:scheme="http" /> 
<data android:scheme="https" /> 
<data 
    android:host="@string/root_host_endpoint" 
    android:pathPattern="/i/.*" /> 
<data 
    android:host="@string/root_host_endpoint" 
    android:pathPattern="/item/.*" /> 
</intent-filter> 
</activity> 
+0

不幸的是,它不处理链接链接 http://example.com https://example.com http://example.com/app https://example.com/app – Bringoff

+0

add