How do you use HTML Web pages and local apps to pass data? After study. Found 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
The following elements are added in the Intent-filte in the androidmanifest manifest file, for example:<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>
The demo sample is 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 get the data from the webpage by this way
It's no fun just to open it, and most importantly. We're going to pass the data, so how do we pass the data?
We can use the above method to pass some data to the local app, so first we change the page. After the code changes:
<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) Consider using 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; }});
How to call the local Android app via HTML page