在Android中,Activity允许有很多种调用方式,其中一个方法是使用 <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="www.google.com"
android:path="m/products/scan"
android:scheme="http" />
</intent-filter>
后来发现,它的调用仍然需要使用intent
Uri uri = Uri.parse("http://www.google.com/m/products/scan");
Intent it = new Intent(Intent.ACTION_VIEW, uri);
startActivity(it);
我是在一个Button的onClick()方法里写的这些代码,这样按这个按钮,就会调用所有符合要求的含有对应<intent-filter>的Activity,在我的手机里,有Chrome Beta、浏览器、快拍二维码、条码扫描器,以及我刚刚创建那个应用的Activity。
嗯嗯,记录一下,以后会经常把日常遇到的问题记下来,方便遇到同样问题的开发者们一起学习!
by HADB of HAOest
2012-6-18 23:13 于宿舍
我的原文地址:http://blog.haoest.com/techpost/several-intent-filters-in-one-activity.html