====== Differences ====== This shows you the differences between two versions of the page.
Both sides previous revision Previous revision | |||
how_to_use_the_android_framework_through_script [2014/09/12 12:13] pierrox |
how_to_use_the_android_framework_through_script [2014/09/15 07:25] (current) pierrox [Sample code] |
||
---|---|---|---|
Line 15: | Line 15: | ||
<sxh javascript;> | <sxh javascript;> | ||
+ | LL.bindClass("android.hardware.Sensor"); | ||
+ | LL.bindClass("android.hardware.SensorEventListener"); | ||
+ | LL.bindClass("android.hardware.SensorManager"); | ||
+ | |||
// replace the id here with your actual compass item id | // replace the id here with your actual compass item id | ||
var COMPASS_ID = 0x1000a; | var COMPASS_ID = 0x1000a; | ||
Line 21: | Line 25: | ||
// retrieve the android sensor service and retrieve an orientation sensor | // retrieve the android sensor service and retrieve an orientation sensor | ||
var sm = LL.getContext().getSystemService(Context.SENSOR_SERVICE); | var sm = LL.getContext().getSystemService(Context.SENSOR_SERVICE); | ||
- | var orientation = sm.getDefaultSensor(android.hardware.Sensor.TYPE_ORIENTATION); | + | var orientation = sm.getDefaultSensor(Sensor.TYPE_ORIENTATION); |
Line 35: | Line 39: | ||
// this is the listener based on the interface function definition | // this is the listener based on the interface function definition | ||
- | var l = new android.hardware.SensorEventListener(i); | + | var l = new SensorEventListener(i); |
// register our listener, which will be called by the Android framework repeatedly | // register our listener, which will be called by the Android framework repeatedly | ||
- | sm.registerListener(l, orientation, android.hardware.SensorManager.SENSOR_DELAY_GAME); | + | sm.registerListener(l, orientation, SensorManager.SENSOR_DELAY_GAME); |
// critical: later, don't forget to unregister this listener to prevent rapid battery consumption | // critical: later, don't forget to unregister this listener to prevent rapid battery consumption | ||
// sm.unregisterListener(l); | // sm.unregisterListener(l); | ||
</sxh> | </sxh> |