使用适用于Android的Xamarin Mono中的intent过滤器处理特定URL

我试图让我的活动处理网址采用mydomain.com或www.mydomain.com形式的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形式的所有网址?

解决方法

您可以添加多个intent过滤器属性
[IntentFilter(
  new[] { Intent.ActionView },DataScheme = "http"
)]
[IntentFilter(
  new[] { Intent.ActionView },DataScheme = "https"
)]
[IntentFilter(
  new[] { Intent.ActionView },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>

相关文章

Android性能优化——之控件的优化 前面讲了图像的优化,接下...
前言 上一篇已经讲了如何实现textView中粗字体效果,里面主要...
最近项目重构,涉及到了数据库和文件下载,发现GreenDao这个...
WebView加载页面的两种方式 一、加载网络页面 加载网络页面,...
给APP全局设置字体主要分为两个方面来介绍 一、给原生界面设...
前言 最近UI大牛出了一版新的效果图,按照IOS的效果做的,页...