native.js不能获取传感器信息,代码如下:
<script type="text/javascript">
document.addEventListener('plusready', function() {
//console.log("所有plus api都应该在此事件发生后调用,否则会出现plus is undefined。"
plus.android.importClass('java.util.List');
plus.android.importClass('java.util.ArrayList');
var SensorEventListener = plus.android.importClass('android.hardware.SensorEventListener');
var Context = plus.android.importClass("android.content.Context");
var mContext = plus.android.runtimeMainActivity();
var SensorManager = plus.android.importClass("android.hardware.SensorManager");
var hevent = plus.android.implements("android.hardware.SensorEventListener", {
onSensorChanged: function(event) {
console.log(event.values);
}
});
var Sensor = plus.android.importClass("android.hardware.Sensor");
var mSensorManager = mContext.getSystemService(Context.SENSOR_SERVICE);
var mList = mSensorManager.getSensorList(Sensor.TYPE_ALL);
let sensor = mSensorManager.getDefaultSensor(Sensor.TYPE_ACCELEROMETER);
mSensorManager.registerListener(hevent, sensor, SensorManager.SENSOR_DELAY_NORMAL);
});
</script>
1 个回复
4***@qq.com