转自:http://blog.csdn.net/qduningning/article/details/37602101
通过用手机的浏览器(内置,第三方都可)访问一个网页,实现点击一个链接启动自己的应用,并传递数据。
首先在Mainifest文件里面对要启动的Activity添加一个过滤器。
在MainActivity接收数据:
写一个最简单的网页:
测试地址: www.erdian.net/m.html
测试结果:
scheme:znn
host:aa.bb
dataString:znn://aa.bb:80/test?p=12&id=1
id:1
path:/test
path1:/test
queryString:p=12&d=1
内置的webview 需要增加一些代码支持scheme
testWv.setWebViewClient(new WebViewClient(
){
@Override
public boolean shouldOverrideUrlLoading(WebView view, String url) {
if (url.startsWith("http") || url.startsWith("https") || url.startsWith("ftp")) {
//不处理http, https, ftp的请求
return false;
}
Intent intent;
try {
intent = Intent.parseUri(url, Intent.URI_INTENT_SCHEME);
} catch (URISyntaxException e) {
return false;
}
intent.setComponent(null);
try {
MainActivity.this.startActivity(intent);
} catch (ActivityNotFoundException e) {
return false;
}
return true;
}
});