Call local Android app code via HTML page _android

Source: Internet
Author: User

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;
}
});

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.