How to call the local Android app via HTML page

Source: Internet
Author: User

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

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.