23模块-proximity【距离传感器】

it2022-05-09  33

Proximity模块管理设备距离传感器,可获取当前设备的接近距离信息,通过plus.proximity可获取设备距离传感管理对象。

 


 

 

<!DOCTYPE html> <html> <head> <meta charset="utf-8"/> <meta name="viewport" content="initial-scale=1.0, maximum-scale=1.0, user-scalable=no"/> <title>心得</title> <script type="text/javascript"> var temp_obj = null; function one(){ plus.proximity.getCurrentProximity(function(e){ alert('获取成功'+e+'厘米'); },function(e){ alert('获取失败'+e.message); }); } function two(){//功能和多次调用 getCurrentProximity 一样 temp_obj = plus.proximity.watchProximity(function(e){ document.getElementById("imglist").innerHTML = "<li>"+parseInt(e)+"度</li>"; //这个距离传感器无非就是判断当前手机是否拿到耳朵旁边了, //也就是听筒旁边的传感器,貌似没法准确检测距离多少厘米 //实际上就只有固定的两个值0或者另外一个值 },function(e){ alert('获取失败'+e.message); }); } function three(){ plus.proximity.clearWatch(temp_obj); } </script> </head> <style> li{line-height: 40px; height: 40px; border-bottom: #ccc dashed 1px;} </style> <body> <ul id="imglist"></ul> <ul> <li οnclick="one()">获取当前设备的接近距离信息</li> <li οnclick="two()">获取设备接近距离信息成功的回调函数</li> <li οnclick="three()">关闭监听设备接近距离变化</li> </ul> </body> </html>

 

转载于:https://www.cnblogs.com/xhrs/p/9329726.html

相关资源:垃圾分类数据集及代码

最新回复(0)