Demand
Open the Android app directly from your mobile browser. If you have installed the specified Android app locally, open it directly, and if you don't have it installed, download the app's installation file directly (and jump to the download page).
Achieve results
Suppose the app is already installed on your phone. is opened directly. If it is not installed, start the download.
Implementation method
1. Set a schema for the startup activity of the Android app, such as the following:
<data android:host= "Splash" android:scheme= "Huiyy"/>
2. When the user clicks on the link in the browser, it creates an invisible iframe dynamically, and lets the IFRAME load the schema in step 1, such as the following:
/*scheme: Must *///scheme_ios: ' huiyy://',//scheme_adr: ' Huiyy://splash ', var IFR = document.createelement (' iframe '); IFR.SRC = Ua.indexof (' os ') > 0? CONFIG.SCHEME_IOS:CONFIG.SCHEME_ADR;
3, assuming that no jump succeeds within the specified time, the current page jumps to the apk (or download page), for example the following:
window.location = Download_url;
HTML code
<!doctype html>CONFIG.SCHEME_IOS:CONFIG.SCHEME_ADR; Ifr.style.display = ' None '; Document.body.appendChild (IFR); var t = setTimeout (function () {var endTime = Date.now (); if (!starttime | | Endtime-starttime < config.timeout + +) {window.location = Config.do Wnload_url; } else {}}, config.timeout); Window.onblur = function () {cleartimeout (t); }} window.addeventlistener ("Domcontentloaded", function () {Document.gete Lementbyid ("Call-app"). AddEventListener (' click ', Openclient,false); }, False); }) () </script> </body>
Androidmanifest.xml
<?xml version= "1.0" encoding= "Utf-8"?><manifest xmlns:android= "http://schemas.android.com/apk/res/android" package= "Com.example.downappdemo" Android:versioncode= "1" android:versionname= "1.0" > <uses-sdk android:minsdkversion= "8" Android: targetsdkversion= "/> <application android:allowbackup=" true "android:icon=" @drawable/ic_launche R "android:label=" @string/app_name "android:theme=" @style/apptheme "> <activity Android Oid:name= "com.example.downappdemo.MainActivity" android:label= "@string/app_name" > <intent-fil ter> <action android:name= "Android.intent.action.MAIN"/> <category android:name = "Android.intent.category.LAUNCHER"/> </intent-filter> <intent-filter> <action android:name= "Android.intent.action.VIEW"/> <category android:name= "android.intent.cate Gory. DEFAULT "/> <category android:name= "Android.intent.category.BROWSABLE"/> <data android:host= "Splash" and Roid:scheme= "Huiyy"/> </intent-filter> </activity> </application></manifest& Gt
Open the Android app directly from the browser