zoukankan      html  css  js  c++  java
  • webapp检测安卓app是否安装并launch

    1. cordova插件

    1)查看所有已安装的安卓app

    https://www.npmjs.com/package/cordova-plugin-packagemanager

    A simple plugin that will return a list of installed applications or all on your smartphone. Retuen uid, dataDir and packageName.

    function successCallback(e) {
        alert(JSON.stringify(e));
    }
    
    function errorCallback(e) {
        alert('Error!' + e);
    }
    
    window.plugins.packagemanager.show(true, successCallback, errorCallback);

    2)检测某安卓app是否已安装

    https://www.npmjs.com/package/cordova-plugin-appavailability

    从1)返回的list of installed applications中找到所需app的scheme,例如高德地图:com.autonavi.minimap。

    var scheme;
    
    if (device.platform === 'iOS') {
        scheme = 'iosamap://';
    }
    else if (device.platform === 'Android') {
        scheme = 'com.autonavi.minimap';
    }
    
    appAvailability.check(
        scheme,       // URI Scheme or Package Name 
        function () {  // Success callback 
            alert(scheme + ' is available :)');
        },
        function () {  // Error callback 
            alert(scheme + ' is not available :(');
        }
    );

    3)launch app

    https://github.com/nchutchind/cordova-plugin-app-launcher

    window.plugins.launcher.launch(
                    { uri: 'androidamap://route?sourceApplication=cortanademoservice&slat=39.979366&slon=116.31028&sname=我的位置&dlat=39.980016&dlon=116.326568&dname=公安局&dev=0&t=0' },
                    successCallback,
                    errorCallback
                );

    2. JavaScript的tricky实现方法

    安装app的情况下,网页会进入后台打开app,网页进入后台后会挂起js的执行,但是这个期间有600-1000ms的时间js仍然会执行,可以利用打开app的延时来判断是否有该app。

    var t = 1000, hasApp = true;
    setTimeout(function () {
        if (!hasApp) {
            cordova.InAppBrowser.open('http://m.amap.com/navigation/carmap/saddr=116.310322%2C39.978957%2C%E5%BE%AE%E8%BD%AF%E5%A4%A7%E5%8E%A6&daddr=116.326568%2C39.980016%2C%E4%B8%AD%E5%85%B3%E6%9D%91%E6%B4%BE%E5%87%BA%E6%89%80&saddr_lonlat=116.310322%2C39.978957%2C%E5%BE%AE%E8%BD%AF%E5%A4%A7%E5%8E%A6&daddr_lonlat=116.326568%2C39.980016%2C%E4%B8%AD%E5%85%B3%E6%9D%91%E6%B4%BE%E5%87%BA%E6%89%80&saddr_typecode=120201&daddr_typecode=130501&saddr_poiid=B0FFFSPTNE&daddr_poiid=B000A7FCSP&maddr=&sort=&addPassing=remove');
        }
        $("#ifr").remove();
    }, 2000);
    
    var t1 = Date.now();
    var ifr = $('<iframe id="ifr"></iframe>')
    ifr.attr('src', 'androidamap://route?sourceApplication=cortanademoservice&slat=39.979366&slon=116.31028&sname=我的位置&dlat=39.980016&dlon=116.326568&dname=公安局&dev=0&t=0');
    $('body').append(ifr);
    setTimeout(function () {
        var t2 = Date.now();
        //delay time 30 may vary for different type of phones
        if (!t1 || t2 - t1 < t + 30) {
            hasApp = false;
        }
    }, t);

    利用iframe的动态加载来尝试打开app。

  • 相关阅读:
    ERROR Function not available to this responsibility.Change responsibilities or contact your System Administrator.
    After Upgrade To Release 12.1.3 Users Receive "Function Not Available To This Responsibility" Error While Selecting Sub Menus Under Diagnostics (Doc ID 1200743.1)
    产品设计中先熟练使用铅笔 不要依赖Axure
    12.1.2: How to Modify and Enable The Configurable Home Page Delivered Via 12.1.2 (Doc ID 1061482.1)
    Reverting back to the R12.1.1 and R12.1.3 Homepage Layout
    常见Linux版本
    网口扫盲二:Mac与Phy组成原理的简单分析
    VMware 8安装苹果操作系统Mac OS X 10.7 Lion正式版
    VMware8安装MacOS 10.8
    回顾苹果操作系统Mac OS的发展历史
  • 原文地址:https://www.cnblogs.com/argenbarbie/p/7808340.html
Copyright © 2011-2022 走看看