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

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.