First, open the Android local app via HTML page
1, first in writing a simple HTML page
Copy Code code as follows:
<meta http-equiv= "Content-type" content= "text/html; Charset=utf-8 ">
<title>insert title here</title>
<body>
<a href= "m://my.com/" > Open app</a><br/>
</body>
2, in the Android local app configuration
Copy Code code as follows:
Add the following elements to the Intent-filte in the androidmanifest manifest file:
<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>
Sample screenshots are as follows:
Then use the "mobile browser" or "WebView" way to open the local HTML page, click on "Open App" to successfully open the local designated app
Second, how to get the data from the Web page through this method
It's not interesting to open it, the most important thing is that we have to pass 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 is modified:
Copy Code code as follows:
<meta http-equiv= "Content-type" content= "text/html; Charset=utf-8 ">
<title>insert title here</title>
<body>
<a href= "M://my.com/?arg0=0&arg1=1" > Open app</a><br/>
</body>
(1). If you open this page through a browser, the way to get the data is:
Copy Code code as follows:
Uri uri = getintent (). GetData (); String test1= uri.getqueryparameter ("arg0"); String test2= uri.getqueryparameter ("arg1");
(2) If you use WebView to access the Web page, the action for obtaining the data is:
Copy Code code as follows:
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;
}
});