Thursday, February 28, 2013
How to Access the Accelerometer Via Javascript in Android
1. Open the Eclipse software on your desktop from the Windows program menu. After the software loads, open your Android project.
2. Double-click the source code file you want to use to access the Accelerometer app. Add a 'SensorManager' class variable. This variable opens the libraries for the app. Add the following code to your source code file:var sensor = (SensorManager) getSystemService(SENSOR_SERVICE);
3. Verify that the accelerator connection was made. You use a boolean variable, which is a variable that returns true or false. The following code returns 'true' to verify that you are connected to the accelerator:boolean connected = sensor.registerListener(this,
SENSOR_ACCELEROMETER,
SENSOR_DELAY_UI);
4. Click the 'Save' button in the main toolbar and click 'Run' to run the new code in the Android emulator.
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment