场景:经过浏览器打开URL或者扫描软件扫描URL来启动本地应用html
Activity配置:android
[html] view plaincopyweb
<application 浏览器
android:allowBackup="true" app
android:icon="@drawable/ic_launcher" spa
android:label="@string/app_name" .net
android:theme="@style/AppTheme" > orm
<activity htm
android:name="com.fyfeng.webviewtest.MainActivity" blog
android:label="@string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</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" /><!-- 定义成浏览器类型,有URL须要处理时会过滤 -->
<data android:scheme="fyfeng" /><!-- 打开以fyfeng协议的URL,这个本身随便定义。 -->
</intent-filter>
</activity>
</application>
第二个intent-filter配置很重要,能够根据本身的须要单独配置一个activity做为调用界面,这里直接使用启动界面做为调用界面。
配置完成上面的intent-filter后在浏览器里面打开以fyfeng://协议开头的URL时系统会调用本地支持fyfeng协议的程序对fyfeng://xxxxx URL进行处理。
例如:
DEMO下载地址:http://download.csdn.net/download/yzwlord/5798277 不收费,随便下。
而后
浏览器打开URL: fyfeng://helloandroid
或扫描二维码:
会直接打开上面刚安装的本地应用,效果图以下。