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