How do you use HTML Web pages and local apps to pass data? After research, found that there are methods, summed up a bit, roughly a few ways
First, open the Android local app via HTML page
1. First, write a simple HTML page
<HTML> <Head> <Metahttp-equiv= "Content-type"content= "text/html; charset=utf-8"> <title>Insert Title here</title> </Head> <Body> <ahref= "m://my.com/">Open app</a><BR/> </Body></HTML>
2, the configuration of the Android local app
Add the following elements to the Intent-filte in the androidmanifest manifest file:<Intent-filter><ActionAndroid:name= "Android.intent.action.VIEW" /> <categoryAndroid:name= "Android.intent.category.DEFAULT" /> <categoryAndroid:name= "Android.intent.category.BROWSABLE" /> <DataAndroid:host= "My.com"Android:scheme= "M" /></Intent-filter>
Examples are as follows:
Then use "mobile browser" or "WebView" way to open this local HTML page, click "Open App" to successfully open the local designated app
How to use this method to get the data brought over by the webpage
Only open is not interesting, the most important thing is that we have to pass the data, then how to pass the data?
We can use the above method to pass some data to the local app, then first we change the Web page, after the code modified:
<HTML> <Head> <Metahttp-equiv= "Content-type"content= "text/html; charset=utf-8"> <title>Insert Title here</title> </Head> <Body> <ahref= "M://my.com/?arg0=0&arg1=1">Open app</a><BR/> </Body></HTML>
(1). If you open this Web page through a browser, the way to get the data is:
Uri uri = getintent (). GetData (); String test1= Uri.getqueryparameter ("arg0"); String test2= Uri.getqueryparameter ("Arg1");
(2) If you use WebView to access the webpage, the operation to get the data is:
Webview.setwebviewclient (Newwebviewclient () {@Override Public Booleanshouldoverrideurlloading (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; }});