How to call a local Android app through an Html webpage

Source: Internet
Author: User

How can we use html web pages and local apps to transmit data? After research, I found that there are still some methods. I have summarized them and there are several methods.

1. Open the Android local app on the html page

1. Compile a simple html page

            
             Insert title here        Open app

2. Local Android app Configuration

Add the following elements to intent-filte in the inventory file of AndroidManifest:
                 
                  
                  
  
 

Example:

Then, use the "mobile browser" or "webview" method to open the local html webpage and click "open APP" to enable the specified local app.

2. How to use this method to obtain data from a webpage

It doesn't make much sense to open it. The most important thing is that we want to transmit data. How can we transmit data?

We can use the above method to pass some data to the local app. First, let's change the webpage. After the code is modified:

            
         Insert title here        Open app

(1). If you open this webpage through a browser, you can obtain data in the following ways:

Uri uri = getIntent().getData();  String test1= uri.getQueryParameter("arg0");  String test2= uri.getQueryParameter("arg1");

(2) If you use webview to access this webpage, the operations for getting data are 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;  }});

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.