1. Set link in html
href=”[scheme]://[host]/[path]?[query]”
The scheme can be set to any value inside the app, and the settings for android and ios are the same
2. If the local application exists, open the app directly; if it does not exist, wait for a period of time Jump to the appstore
You need to determine the browser under the ios or android platform, you need to determine the WeChat browser
XML/HTML CodeCopy content to clipboard
- <code class="hljs" javascript="">var openApp = function () {
-
var btnOpenApp = document.getElementById(open-app);
-
btnOpenApp.onclick = function () {
- //Open local application function
-
var open=function(url){
- var timeout;
- function try_to_open_app() {
-
timeout = setTimeout(function(){
-
window.location.href=url;
- console.log()
- }, );
- }
- try_to_open_app();
- }
- if (/android/i.test(navigator.userAgent)) {
- //alert(This is Android'browser.);//This is the browser for Android platform
- if (/MicroMessenger/i.test(navigator.userAgent)) {
- alert(This is MicroMessenger browser, please use local browser to open);//This is the browser under WeChat platform
- }
- else {
- open(andorid application market url);
- }
- }
- if (/(iPhone|iPad|iPod|iOS)/i.test(navigator.userAgent)) {
- //alert(This is iOS'browser.);//This is the browser for iOS platform
- if (/MicroMessenger/i.test(navigator.userAgent)) {
- alert (WeChat’s built-in browser does not support opening local applications, please click on the upper right corner to open it with a local browser); //This is the browser under the WeChat platform
- }
- else {
- open(ios application market url);
- }
- }
- };
-
}code>
Android配置
XML/HTML Code复制内容到剪贴板
- <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
XML/HTML Code复制内容到剪贴板
- <%@ 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配置示例
Open app
Open Market
Open Market Details
Android获取参数:
XML/HTML Code复制内容到剪贴板
- 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 arg=uri.getQueryParameter("arg");
-
String arg=uri.getQueryParameter("arg");
- }else{
- view.loadUrl(url);
- }
- return true;
- }
- });
以上所述是小编给大家介绍的Android本地应用打开方法——通过html5写连接 ,希望对大家有所帮助!