5

Próbuję użyć adresów URL dla operacji o postaci mydomain.com lub www.mydomain.com w obu schematach: http i https. Obecnie atrybut IntentFilter dla mojej działalności wygląda następująco:Obsługa określonych adresów URL z filtrami zamiany w Xamarin Mono na system Android

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

który generuje to w manifeście, i nie wydaje się działać dla każdego z wymaganych konfiguracjach URL:

<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> 

Jak czy mogę zmienić ten atrybut, aby moja aktywność obsługiwała wszystkie adresy URL w postaci http (s): // (www.) mydomain.com?

Odpowiedz

2

Można dodać wiele filtrów zamiaru atrybuty

[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 {} 

otrzymany xml będzie

<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

Czy potrzebuję jeszcze dwóch instancji atrybutu IntentFilter w celu dołączenia aliasu "www" dla obu schematów? –

+0

Możesz używać symboli wieloznacznych do subdomen bez dodawania dodatkowych filtrów intencji. –

+0

Byłoby miło, gdyby do odpowiedzi dołączyć przykład użycia symbolu wieloznacznego. –

2

sprężonego pojedynczy IntentFilter:

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

wygeneruje następujący węzła 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> 
Powiązane problemy