应用中经常要启动其他应用,比如:打开市场为自己的应用打分、强制用户更新应用、强制Chrome打开网页等等。在调用之前,你有必要知道要调用的应用是否在机器上已经安装。(很多通过URL Scheme启动的应用如果没有安装的话就没有任何提示)
这个插件很小,也很简单,但是还是比较实用的。在Android环境下它通PackageManager来检查ID是否存在,在iOS环境下通过canOpenURL检查机器是否安装了该应用。
插件地址:
https://github.com/ohh2ahh/AppAvailability
(1)创建工程
引用
cordova create AppAvailability com.rensanning.cordova AppAvailability
cd AppAvailability
cordova platform add android
(2)安装plugin
引用
cordova plugin add org.apache.cordova.device
cordova plugin add https://github.com/ohh2ahh/AppAvailability.git
(3)修改代码
if (device.platform.toLowerCase() == 'ios') {
appAvailability.check(
'twitter://', // URI Scheme
function() { // Success callback
alert('Twitter is available');
},
function() { // Error callback
alert('Twitter is not available');
}
);
}
if (device.platform.toLowerCase() == 'android') {
appAvailability.check(
'com.twitter.android', // URI Scheme
function() { // Success callback
alert('Twitter is available');
},
function() { // Error callback
alert('Twitter is not available');
}
);
}
(4)编译后安装到手机上
引用
cordova build
- 大小: 18.5 KB
- 大小: 18.3 KB
分享到:
相关推荐
NULL 博文链接:https://rensanning.iteye.com/blog/2034061
NULL 博文链接:https://rensanning.iteye.com/blog/2072034
cordova-plugin-app-update App updater for Cordova/PhoneGap Demo Try it yourself: Just clone and install this demo. cordova-plugin-app-update-DEMO :tada: 如果喜欢它,请别忘了给我一颗鼓励的星 Support ...
实实在在经过ant编译的cordova-2.9.1.jar 而不是有些人坑蒙拐骗的rar文件
NULL 博文链接:https://rensanning.iteye.com/blog/2032663
NULL 博文链接:https://rensanning.iteye.com/blog/2034026
cordova扫码插件phonegap-plugin-barcodescanner,修复了在ios10上面的内存泄漏导致的闪退bug
如果没有,说明插件使用不当,尝试重新安装,如果有这些信息,说明Key与当前程序AndroidManifest.xml 中的package名不一致,请检查Key的申请信息是否正确 四,查看当前安装了哪些插件 cordova plugin ls 五,...
热更新时,我们执行命令 npm install -g cordova-hot-code-push-cli安装插件,但运行cordova-hcp server会报错,如:Could not create tunnel: { Error: ngrok is not yet ready to start tunnels...,这时我们找到...
NULL 博文链接:https://rensanning.iteye.com/blog/2042543
NULL 博文链接:https://rensanning.iteye.com/blog/2023480
Ionic3.x+、Angular4.x+ Cordova 介 绍以及Ionic3.x+环境搭建 一、Ionic 介绍............................................................................................................................1 二...
Cordova 3.x(aka PhoneGap)的基础知识、实用插件、源码分析、实例开发。
cordova-plugin-firebase-analytics, 用于Firebase分析的Cordova插件 cordova-plugin-firebase-analytics Firebase分析插件的Cordova插件。安装cordova plugin add cordova-plugin-firebase-analyti
cordova-screenshot cordova截屏插件 document.addEventListener("deviceready", init, false); function init() { document.querySelector("#share").addEventListener("touchend", function() { navigator....