2016-07-10 2 views
2

J'ai des activités que j'ai besoin de les relier en profondeur à deux URLs, mais chaque fois que je clique sur une URL, elle montre les deux activités en même temps, alors Comment puis-je définir le intent-filter? 1 URL spécifique?Les liens profonds Android ne fonctionnent pas correctement

1er URL http://www.sample.com/newcars/models/33

et son activité

<activity 
     android:name=".ui.activities.NewCarModelEngineActivity" 
     android:label="@string/newCars" 
     android:screenOrientation="sensorPortrait"> 
     <intent-filter> 
      <action android:name="android.intent.action.VIEW"/> 

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

      <data 
       android:host="sample.com" 
       android:pathPrefix="/newcars/engines/" 
       android:scheme="http"/> 
      <data 
       android:host="www.sample.com" 
       android:pathPrefix="/newcars/engines/" 
       android:scheme="http"/> 

      <data 
       android:host="newengine" 
       android:pathPattern="/..*/..*/..*" 
       android:scheme="sample"></data> 

     </intent-filter> 
    </activity> 

2ème URL http://www.sample.com/usedcars/engines/9876543 et son activité

<activity 
     android:name=".ui.activities.UsedCarEngineDetailsActivity" 
     android:label="@string/usedCars" 
     android:screenOrientation="sensorPortrait"> 
     <intent-filter > 
      <action android:name="android.intent.action.VIEW"/> 

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

      <data 
       android:host="sample.com" 
       android:pathPrefix="/usedcars/engines/" 
       android:scheme="http"/> 
      <data 
       android:host="www.sample.com" 
       android:pathPrefix="/usedcars/engines/" 
       android:scheme="http"/> 
      <data 
       android:host="usedengine" 
       android:pathPattern="/..*/..*/..*" 
       android:scheme="sample"></data> 
     </intent-filter> 
    </activity> 

Répondre

0

Essayez de mettre vos scheme="sample" données dans un filtre d'intention distincts. Cela semble être un bug, mais parfois Android ignore simplement le préfixe du chemin lorsqu'un autre est présent et vide ou avec des caractères génériques. Vous pouvez également utiliser host="*sample.com" pour faire correspondre à la fois sample.com et www.sample.com.

Ex pour votre première activité:

<activity 
    android:name=".ui.activities.NewCarModelEngineActivity" 
    android:label="@string/newCars" 
    android:screenOrientation="sensorPortrait"> 

    <intent-filter> 
     <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" 
      android:host="*sample.com" 
      android:pathPrefix="/newcars/engines/" /> 

    </intent-filter> 

    <intent-filter> 
     <action android:name="android.intent.action.VIEW"/> 

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

     <data 
      android:scheme="sample" 
      android:host="newengine" 
      android:pathPattern="/..*/..*/..*" /> 

    </intent-filter> 

</activity> 
+0

Je viens essayé et ça ne fonctionne pas, il montre encore les deux activités. –