Cordova插件在 deviceready 事件后可用
一、 获取有关用户设备的信息
1.1 安装:cordova plugin add cordova-plugin-device
1.2 使用(打印信息):console.log(device)
获取到的设备信息内容如下:
{
"available":true,
"platform":"Android",
"version":"10",
"uuid":"5f98dfa80235196c",
"cordova":"10.1.2",
"model":"TC21",
"manufacturer":"Zebra Technologies",
"isVirtual":false,
"serial":"unknown",
"isiOSAppOnMac":null,
"sdkVersion":"29"
}
二、手机状态栏的消息通知
2.1 安装: cordova plugin add cordova-plugin-local-notification
2.2 使用:
cordova.plugins.notification.local.schedule({
title: 'title标题'
text: 'text文本'
});
三、 接收外部广播消息
3.1 安装:cordova plugin add cordova-plugin-broadcaster
3.2 使用:
// 安卓机监听广播
function listenBroadcaster () {
if (cordova && cordova.platformId === 'android') {
const listener = (e: any) => {
// TODO: 接收到广播消息后的处理
// 'com.symbol.datawedge.data_string'是自定义的广播额外字符串
console.log(e['com.symbol.datawedge.data_string']);
};
const isGlobal = true;
// 'com.ce.drs' 是手机中定义的广播操作名称
window.broadcaster.addEventListener(
'com.ce.drs',
isGlobal,
listener,
);
}
};
3.3 取消监听时: window.broadcaster._channels = {};
四、打印cordova信息:console.log(cordova)
{
"version":"9.1.0",
"platformVersion":"9.1.0",
"platformId":"android",
"callbackId":1076142790,
"callbacks":{
"CoreAndroid1076142784":{
"fail":null
},
"LocalNotification1076142788":{
"fail":null
}
},
"callbackStatus":{
"NO_RESULT":0,
"OK":1,
"CLASS_NOT_FOUND_EXCEPTION":2,
"ILLEGAL_ACCESS_EXCEPTION":3,
"INSTANTIATION_EXCEPTION":4,
"MALFORMED_URL_EXCEPTION":5,
"IO_EXCEPTION":6,
"INVALID_ACTION":7,
"JSON_EXCEPTION":8,
"ERROR":9
},
"plugins":{
"notification":{
"badge"::{
"_config":{
"indicator":"badge",
"autoClear":false
}
},
"local":{
"core":{
"_defaults":{
"actionGroupId":null,
"actions":[
],
"attachments":[
],
"autoClear":false,
"badge":null,
"channel":null,
"color":null,
"data":null,
"defaults":0,
"foreground":false,
"group":null,
"groupSummary":false,
"icon":null,
"id":0,
"launch":true,
"led":true,
"lockscreen":true,
"mediaSession":null,
"number":0,
"priority":0,
"progressBar":false,
"showWhen":true,
"silent":false,
"smallIcon":"res://icon",
"sound":true,
"sticky":false,
"summary":null,
"text":"",
"title":"",
"trigger":{
"type":"calendar"
},
"vibrate":false,
"wakeup":true
},
"_listener":{
}
}
}
}
}
}