弓背霞明剑照霜,秋风走马出咸阳。这篇文章主要讲述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);
【webapp检测安卓app是否安装并launch】利用iframe的动态加载来尝试打开app。
推荐阅读
- Linux/Android——input_handler之evdev
- Linux/Android——输入子系统input_event传递
- Android 引入外部模块编译选择
- com/android/dx/command/dexer/Main : Unsupported major.minor version 52.0
- android 判断左右滑动,上下滑动的GestureDetector简单手势检测
- C .Thunder——爱阅app(测评人(方铭))
- Apple Tree POJ - 2486
- B.欢迎来怼——博客园安卓app(测评人(阚博文))
- Mapper.xml中对象的关联