在Xamarin Mono for Android中使用意图过滤器处理特定URL
我正试图让我的活动以在Xamarin Mono for Android中使用意图过滤器处理特定URL,android,xamarin,xamarin.android,android-manifest,intentfilter,Android,Xamarin,Xamarin.android,Android Manifest,Intentfilter,我正试图让我的活动以mydomain.com或www.mydomain.com的形式处理URL,同时使用http和https方案。当前,“我的活动”的IntentFilter属性如下所示: [IntentFilter( new[] { Intent.ActionView }, Categories = new[] { Intent.CategoryDefault, Intent.CategoryBrowsable }, DataHost = "mydomain.com", Dat
mydomain.com
或www.mydomain.com
的形式处理URL,同时使用http
和https
方案。当前,“我的活动”的IntentFilter属性如下所示:
[IntentFilter(
new[] { Intent.ActionView },
Categories = new[] { Intent.CategoryDefault, Intent.CategoryBrowsable },
DataHost = "mydomain.com",
DataScheme = "http"
)]
它在清单中生成此项,并且似乎不适用于任何所需的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>
如何更改此属性,以便我的活动能够处理http(s)://(www.mydomain.com)格式的所有URL?您可以添加多个意图过滤器属性
[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 {}
生成的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: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>
压缩单意图过滤器:
[
IntentFilter
(
new[] { Intent.ActionView },
Categories = new[]
{
Intent.CategoryDefault,
Intent.CategoryBrowsable
},
DataSchemes = new[] { "http", "https" },
DataHosts = new[] { "*.xamarin.com", "xamarin.com" },
DataMimeType = "text/plain"
)
]
将生成以下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>
我是否需要另外两个IntentFilter属性实例才能为两个方案添加“www”别名?您可以在子域中使用通配符,而无需添加其他intent筛选器。如果您在答案中添加一个通配符用法的示例,那就太好了。通配符*.mydomain.com
是否正确不包括第二层域本身,即mydomain.com
?这比重复属性要好得多。