Html5 write link to open ios and android local applications

Source: Internet
Author: User

Html5 write link to open ios and android local applications

1,Set link in html

Href = "[scheme]: // [host]/[path]? [Query]"

Scheme can be set to any one in the app, and the android and ios settings are the same.

2If the local application exists, open the app directly. If the application does not exist, jump to the appstore for a period of time.
Determine whether the browser is ios or android.

Var openApp = function () {var btnOpenApp = document. getElementById (open-app); btnOpenApp. onclick = function () {// open the local application function var open = function (url) {var timeout; function try_to_open_app () {timeout = setTimeout (function () {window. location. href = url; console. log (22)}, 10);} try_to_open_app ();} if (/android/I. test (navigator. userAgent) {// alert (This is Android 'browser .); // This is the browser if (/MicroMessenger/I. test (navigator. userAgent) {alert (This is MicroMessenger browser, please open it in a local browser); // This is a platform browser} else {open (andorid app market url );}} if (/(iPhone | iPad | iPod | iOS)/I. test (navigator. userAgent) {// alert (This is iOS 'browser .); // This is the browser if (/MicroMessenger/I. test (navigator. userAgent) {alert (the built-in browser does not support opening local applications. Please click to open the local browser in the upper right corner ); // This is the platform's browser} else {open (ios app market url );}}};}

Android Configuration

<activity android:name=".ui.UploadActivity" android:screenorientation="portrait">            <intent-filter>                <data android:scheme="http" android:host="192.168.167.33" android:port="8088" android:path="/mi-tracker-web/download.html">                <action android:name="android.intent.action.VIEW">                <category android:name="android.intent.category.DEFAULT">                <category android:name="android.intent.category.BROWSABLE">            </category></category></action></data></intent-filter>        </activity>
            Open Application
<%@ page language="java" contentType="text/html; charset=ISO-8859-1"    pageEncoding="ISO-8859-1"%>
<Script type = "text/javascript"> window. location = "market: // search? Q = com. singtel. travelbuddy. android "; </script>
String str = "market://details?id=" + getPackageName(); Intent localIntent = new Intent("android.intent.action.VIEW"); localIntent.setData(Uri.parse(str)); startActivity(localIntent);

HTML configuration example

Open app

Open Market

Open Market Details

Android get parameters:

Uri uri = getIntent().getData();  String test1= uri.getQueryParameter("arg0");  String test2= uri.getQueryParameter("arg1");
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.