User Tools

Site Tools


how_to_use_the_android_framework_through_script

====== Differences ====== This shows you the differences between two versions of the page.

Link to this comparison view

Next revision
Previous revision
how_to_use_the_android_framework_through_script [2014/09/12 12:11]
pierrox created
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
 var COMPASS_ID = 0x1000a; var COMPASS_ID = 0x1000a;
 +var compass = LL.getCurrentDesktop().getItemById(COMPASS_ID);​
  
 +// 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 accel = sm.getDefaultSensor(android.hardware.Sensor.TYPE_ORIENTATION);​+var orientation ​= sm.getDefaultSensor(Sensor.TYPE_ORIENTATION);​
  
- 
-var compass = LL.getCurrentDesktop().getItemById(COMPASS_ID);​ 
  
 // this is the interface function definition // this is the interface function definition
Line 34: 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, ​accelandroid.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>​
how_to_use_the_android_framework_through_script.1410523891.txt.gz · Last modified: 2014/09/12 12:11 by pierrox