5

Sto tentando di gestire la mia attività url prendendo il formato mydomain.com o www.mydomain.com con entrambi gli schemi http e https. Attualmente l'attributo IntentFilter per la mia attività è simile al seguente:Gestione di URL specifici con filtri intent in Xamarin Mono per Android

[IntentFilter(
    new[] { Intent.ActionView }, 
    Categories = new[] { Intent.CategoryDefault, Intent.CategoryBrowsable }, 
    DataHost = "mydomain.com", 
    DataScheme = "http" 
)] 

che genera questo nel manifesto, e che non sembra funzionare per una qualsiasi delle configurazioni url richiesti:

<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="mydomain.com" android:scheme="http" /> 
</intent-filter> 

Come posso modificare questo attributo in modo che la mia attività gestisca tutti gli URL del formato http (s): // (www.) mydomain.com?

risposta

2

È possibile aggiungere filtri intento multipla attributi

[IntentFilter(
    new[] { Intent.ActionView }, 
    Categories = new[] { Intent.CategoryDefault, Intent.CategoryBrowsable }, 
    DataHost = "mydomain.com", 
    DataScheme = "http" 
)] 
[IntentFilter(
    new[] { Intent.ActionView }, 
    Categories = new[] { Intent.CategoryDefault, Intent.CategoryBrowsable }, 
    DataHost = "mydomain.com", 
    DataScheme = "https" 
)] 
[IntentFilter(
    new[] { Intent.ActionView }, 
    Categories = new[] { Intent.CategoryDefault, Intent.CategoryBrowsable }, 
    DataHost = "*.mydomain.com", 
    DataScheme = "http" 
)] 
[IntentFilter(
    new[] { Intent.ActionView }, 
    Categories = new[] { Intent.CategoryDefault, Intent.CategoryBrowsable }, 
    DataHost = "*.mydomain.com", 
    DataScheme = "https" 
)] 
public class MyActivity : Activity {} 

l'XML risultante sarà

<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="mydomain.com" android:scheme="http" /> 
</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:host="mydomain.com" android:scheme="https" /> 
</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:host="*.mydomain.com" android:scheme="http" /> 
</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:host="*.mydomain.com" android:scheme="https" /> 
</intent-filter> 
+0

Avrei bisogno di altre due istanze dell'attributo IntentFilter per aggiungere l'alias "www" per entrambi gli schemi? –

+0

È possibile utilizzare i caratteri jolly per i sottodomini senza aggiungere ulteriori filtri di intent. –

+0

Sarebbe bello se alla tua risposta venisse aggiunto un esempio di utilizzo di caratteri jolly. –

2

compressa singola IntentFilter:

[ 
    IntentFilter 
    (
     new[] { Intent.ActionView }, 
     Categories = new[] 
      { 
       Intent.CategoryDefault, 
       Intent.CategoryBrowsable 
      }, 
     DataSchemes = new[] { "http", "https" }, 
     DataHosts = new[] { "*.xamarin.com", "xamarin.com" }, 
     DataMimeType = "text/plain" 
    ) 
] 

genererà seguente nodo AndroidManifest.xml:

<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:mimeType="text/plain" /> 
    <data android:host="*.xamarin.com" /> 
    <data android:host="xamarin.com" /> 
    <data android:scheme="http" /> 
    <data android:scheme="https" /> 
    </intent-filter> 
Problemi correlati