Android中一个Activity多个intent-filter的调用方法
16lz
2021-12-04
在Android中,Activity允许有很多种调用方式,其中一个方法是使用 <intent-filter>。
比如:
一开始我以为,在浏览器中键入“http://www.google.com/m/products/scan”就可以调用了的,结果发现浏览器只是正常打开它 T.T
后来发现,它的调用仍然需要使用intent
我是在一个Button的onClick()方法里写的这些代码,这样按这个按钮,就会调用所有符合要求的含有对应<intent-filter>的Activity,在我的手机里,有Chrome Beta、浏览器、快拍二维码、条码扫描器,以及我刚刚创建那个应用的Activity。
嗯嗯,记录一下,以后会经常把日常遇到的问题记下来,方便遇到同样问题的开发者们一起学习!
by HADB of HAOest
2012-6-18 23:13 于宿舍
比如:
<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>
一开始我以为,在浏览器中键入“http://www.google.com/m/products/scan”就可以调用了的,结果发现浏览器只是正常打开它 T.T
后来发现,它的调用仍然需要使用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 于宿舍
更多相关文章
- android倒计时(整理)
- 手工下载android sdk或者system images等等
- android源码分析(一) - 语言切换机制
- Android调用摄像头闪退
- Android(安卓)设置隐式意图
- android scroller类的使用
- Android(安卓)进度条
- Android横竖屏切换总结(Android资料收藏)
- vue.js的h5页面与android(WebViewJavascriptBridge) / ios(windo