识别图片中的二维码、条码,返回结果数组。
//放一个 id 为 htmlFileInput 文件选择标签到页面上,<input type="file" accept="image/*" id="htmlFileInput" />
const htmlFileInput = document.getElementById('htmlFileInput');
if (htmlFileInput.files.length > 0) {
const reader = new FileReader();
reader.onload = function(event) {
const buffer = new Uint8Array(event.target.result);
//识别
ymx.detectCode({
imageData: buffer
})
.then(res => {
alert(JSON.stringify(res));
})
.catch(err => {
alert(JSON.stringify(err));
});
};
reader.onerror = function() {
alert('读取文件失败');
};
//读取文件
const file = htmlFileInput.files[0];
reader.readAsArrayBuffer(file);
} else {
alert("请选择文件");
}
//本地临时文件
const localFile = 'fs://temp/img.png';
try {
//下载图片
await ymx.downloadFile({
url: 'https://www.yimenapp.com/assets/img/qr-test.png',
filePath: localFile
});
//识别
const res = await ymx.detectCode({
filePath: localFile
});
alert(JSON.stringify(res));
} catch (err) {
alert(err.message);
} finally {
//删除临时文件
const fs = ymx.getFileSystemManager();
if (await fs.exist({ path: localFile })) {
await fs.remove({ path: localFile });
}
}
获取设备电池信息
获取是否保持常亮状态
获取屏幕亮度
开始监听加速计数据
开始监听陀螺仪数据
设备