设备
获取设备电池信息
const res = await ymx.getBatteryInfo();alert(JSON.stringify(res)); 复制
const res = await ymx.getBatteryInfo();alert(JSON.stringify(res));
获取是否保持常亮状态
ymx.getKeepScreenOn() .then(res => { alert(res.isKeepScreenOn ? '常亮' : '不常亮'); }); 复制
ymx.getKeepScreenOn() .then(res => { alert(res.isKeepScreenOn ? '常亮' : '不常亮'); });
获取屏幕亮度
ymx.getScreenBrightness() .then(res => { alert(JSON.stringify(res)); }); 复制
ymx.getScreenBrightness() .then(res => { alert(JSON.stringify(res)); });
检测设备是否支持加速计
const isSupport = await ymx.isSupportAccelerometer();alert(isSupport ? '支持' : '不支持'); 复制
const isSupport = await ymx.isSupportAccelerometer();alert(isSupport ? '支持' : '不支持');
检测设备是否支持罗盘
const isSupport = await ymx.isSupportCompass();alert(isSupport ? '支持' : '不支持'); 复制
const isSupport = await ymx.isSupportCompass();alert(isSupport ? '支持' : '不支持');
检测设备是否支持陀螺仪
const isSupport = await ymx.isSupportGyroscope();alert(isSupport ? '支持' : '不支持'); 复制
const isSupport = await ymx.isSupportGyroscope();alert(isSupport ? '支持' : '不支持');
拨打电话
await ymx.makePhoneCall({ // 示例号码 phoneNumber: '13800138000'}); 复制
await ymx.makePhoneCall({ // 示例号码 phoneNumber: '13800138000'});
移除加速计数据事件的监听函数,不传 listener 则移除所有监听函数
可选
//移除全部加速计监听器await ymx.offAccelerometerChange(); 复制
//移除全部加速计监听器await ymx.offAccelerometerChange();
移除罗盘数据事件的监听函数,不传 listener 则移除所有监听函数
//移除全部罗盘监听器await ymx.offCompassChange(); 复制
//移除全部罗盘监听器await ymx.offCompassChange();
移除陀螺仪数据事件的监听函数,不传 listener 则移除所有监听函数
//移除全部陀螺仪监听器await ymx.offGyroscopeChange(); 复制
//移除全部陀螺仪监听器await ymx.offGyroscopeChange();
监听加速计数据事件
await ymx.onAccelerometerChange((res) => { console.log(`Accelerometer x:${res.x}, y:${res.y}, z:${res.z}`);}); 复制
await ymx.onAccelerometerChange((res) => { console.log(`Accelerometer x:${res.x}, y:${res.y}, z:${res.z}`);});
监听罗盘数据事件
await ymx.onCompassChange((res) => { console.log(`Compass x:${res.x}, y:${res.y}, z:${res.z}`);}); 复制
await ymx.onCompassChange((res) => { console.log(`Compass x:${res.x}, y:${res.y}, z:${res.z}`);});
监听陀螺仪数据事件
await ymx.onGyroscopeChange((res) => { console.log(`Gyroscope x:${res.x}, y:${res.y}, z:${res.z}`);}); 复制
await ymx.onGyroscopeChange((res) => { console.log(`Gyroscope x:${res.x}, y:${res.y}, z:${res.z}`);});
调起客户端扫码界面进行扫码
const res = await ymx.scanCode({ scanType: ['barCode', 'qrCode']});alert(JSON.stringify(res)); 复制
const res = await ymx.scanCode({ scanType: ['barCode', 'qrCode']});alert(JSON.stringify(res));
ymx.scanCode({ onlyFromCamera: true}).then(res => { alert(JSON.stringify(res));}); 复制
ymx.scanCode({ onlyFromCamera: true}).then(res => { alert(JSON.stringify(res));});
拉起手机发送短信界面
设置是否保持常亮状态
ymx.setKeepScreenOn({ keepScreenOn: true}).then(() => { alert('已开启屏幕常亮');}); 复制
ymx.setKeepScreenOn({ keepScreenOn: true}).then(() => { alert('已开启屏幕常亮');});
ymx.setKeepScreenOn({ keepScreenOn: false}).then(() => { alert('已关闭屏幕常亮');}); 复制
ymx.setKeepScreenOn({ keepScreenOn: false}).then(() => { alert('已关闭屏幕常亮');});
设置屏幕亮度
ymx.setScreenBrightness({ value: 0.8}).then(() => { alert('已设置');}); 复制
ymx.setScreenBrightness({ value: 0.8}).then(() => { alert('已设置');});
开始监听加速计数据
await ymx.startAccelerometer({ interval: 200}); 复制
await ymx.startAccelerometer({ interval: 200});
开始监听罗盘数据
await ymx.startCompass({ interval: 200}); 复制
await ymx.startCompass({ interval: 200});
开始监听陀螺仪数据
await ymx.startGyroscope({ interval: 200}); 复制
await ymx.startGyroscope({ interval: 200});
停止监听加速计数据
await ymx.stopAccelerometer(); 复制
await ymx.stopAccelerometer();
停止监听罗盘数据
await ymx.stopCompass(); 复制
await ymx.stopCompass();
停止监听陀螺仪数据
await ymx.stopGyroscope(); 复制
await ymx.stopGyroscope();
使手机发生较长时间的振动(400 ms)
await ymx.vibrateLong(); 复制
await ymx.vibrateLong();
使手机发生较短时间的振动(15 ms)
await ymx.vibrateShort({ type: 'medium'}); 复制
await ymx.vibrateShort({ type: 'medium'});
设备