Open the Android app directly from the browser

Source: Internet
Author: User

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

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.