How to Access the Accelerometer Via Javascript in Android

The Android Accelerometer app installs on an Android phone so you can monitor the phone's environment. The app alerts you to any issues, and it watches for any apps that slow down the phone's service. You can access the accelerometer from JavaScript in your Android Eclipsed development environment. The accelerometer lets you report statistics about the phones speed and security to your users as they download data.

Instructions

    • 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.

Related Searches:

References

Comments

Related Ads

Featured