如何使用html网页和本地app进行传递数据呢?通过研究,发现仍是有方法的,总结了一下,大体有一下几种方式html
更新一下吧,这篇日志写于2013年11月,离如今已经好久了,依然不少朋友在查阅。目前应该有更新的技术。你们也去补充一下。另外评论里面有朋友说只有webkit内核的浏览器能够使用,这个我没有去作过验证,你们使用的时候,能够参考一下。android
---update in 2015.11.13web
1、经过html页面打开Android本地的app浏览器
一、首先在编写一个简单的html页面app
<html> <head> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> <title>Insert title here</title> </head> <body> <a href="m://my.com/">打开app</a><br/> </body> </html>
二、在Android本地app的配置ide
在AndroidManifest的清单文件里的intent-filte中加入以下元素: <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="my.com" android:scheme="m" /> </intent-filter>
示例截图以下:ui
而后使用“手机浏览器”或者“webview”的方式打开这个本地的html网页,点击“打开APP”便可成功开启本地的指定的appurl
2、如何经过这个方法获取网页带过来的数据spa
只能打开就没什么意思了,最重要的是,咱们要传递数据,那么怎么去传递数据呢?日志
咱们能够使用上述的方法,把一些数据传给本地app,那么首先咱们更改一下网页,代码修改后:
<html> <head> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> <title>Insert title here</title> </head> <body> <a href="m://my.com/?arg0=0&arg1=1">打开app</a><br/> </body> </html>
(1).假如你是经过浏览器打开这个网页的,那么获取数据的方式为:
Uri uri = getIntent().getData(); String test1= uri.getQueryParameter("arg0"); String test2= uri.getQueryParameter("arg1");
(2)若是使用webview访问该网页,获取数据的操做为:
webView.setWebViewClient(new WebViewClient(){ @Override public boolean shouldOverrideUrlLoading(WebView view, String url) { Uri uri=Uri.parse(url); if(uri.getScheme().equals("m")&&uri.getHost().equals("my.com")){ String arg0=uri.getQueryParameter("arg0"); String arg1=uri.getQueryParameter("arg1"); }else{ view.loadUrl(url); } return true; } });