ps: 插件的使用要都放在 onDeviceReady里面document.addEventListener("deviceready", onDeviceReady, false);
获取app的通讯录
- 安装插件
cordova plugin add cordova-plugin-contacts
- 使用插件
let options = new ContactFindOptions();
options.filter = "";
options.multiple = true;
options.desiredFields = [navigator.contacts.fieldType.id];
options.hasPhoneNumber = true;
let fields = ["displayName", "name","phoneNumbers"];
navigator.contacts.find(fields, onSuccess, onError);
function onSuccess(data){
data = data.map(item => {
let temObj = {
displayName: item.displayName,
name: item.name,
phoneNumbers: item.phoneNumbers,
email: item.email,
address: item.address
}
return temObj;
})
}
function onError(){}
获取安卓短信内容插件
- 插件安装
cordova plugin add cordova-plugin-smslog
- 使用插件
document.addEventListener("deviceready", onDeviceReady, false);
function onDeviceReady() {
window.plugins.smsLog && window.plugins.smsLog.getSmsLog(null, true, success, error)
}
function success(sms){}
function error(){}
长按保存图片插件
- cordova plugin add https://github.com/devgeeks/Canvas2ImagePlugin.git
- 使用插件
<canvas id="myCanvas" width="165px" height="145px"></canvas>
function onDeviceReady()
{
window.canvas2ImagePlugin.saveImageDataToLibrary(
function(msg){
console.log(msg);
},
function(err){
console.log(err);
},
document.getElementById('myCanvas')
);
}