I'm using windows and I seem to need that HDAPS thing. (The path written next to the checkbox shows a linux path).
Regards,
plusminus
package com.neel;
import android.app.Activity;
import android.os.Bundle;
import android.hardware.Sensors;
public class Accelerometer {
/** True when the Accelerometer-functionality is basically available. */
boolean accelerometerAvailable = false;
boolean isEnabled = false;
/**
* Sets up an AccelerometerReader. Checks if Accelerometer is available on
* this device and throws UnsupportedOperationException if not .
*
* @param doEnable :
* enables the devices Accelerometer
* initially (if sensor available)
* @throws UnsupportedOperationException
* if Accelerometer is not available on this device.
*/
public Accelerometer(boolean doEnable)
throws UnsupportedOperationException {
/* Check once here in the constructor if an
* Accelerometer is available on this device. */
for (String aSensor : Sensors.getSupportedSensors())
if (aSensor.equals(Sensors.SENSOR_ACCELEROMETER))
accelerometerAvailable = true;
if (!accelerometerAvailable)
throw new UnsupportedOperationException(
"Accelerometer is not available.");
if (doEnable)
setEnableAccelerometer(true);
}
/**
* En/Dis-able the Accelerometer.
*
* @param doEnable
* <code>true</code> for enable.<br>
* <code>false</code> for disable.
* @throws UnsupportedOperationException
*/
public void setEnableAccelerometer(boolean doEnable)
throws UnsupportedOperationException {
if (!accelerometerAvailable)
throw new UnsupportedOperationException(
"Accelerometer is not available.");
/* If should be enabled and not already is: */
if (doEnable && !this.isEnabled) {
Sensors.enableSensor(Sensors.SENSOR_ACCELEROMETER);
this.isEnabled = true;
} else /* If should be disabled and not already is: */
if (!doEnable && this.isEnabled) {
Sensors.disableSensor(Sensors.SENSOR_ACCELEROMETER);
this.isEnabled = false;
}
}
/**
* Read out the values currently provided by the Accelerometer.
*
* @return the current Accelerometer-values.
* @throws UnsupportedOperationException
* if Accelerometer is not available on this device.
* @throws IllegalStateException
* if Accelerometer was set to disabled.
*/
public float[] readAccelerometer() throws UnsupportedOperationException, IllegalStateException {
if (!accelerometerAvailable)
throw new UnsupportedOperationException(
"Accelerometer is not available.");
if (!this.isEnabled)
throw new IllegalStateException(
"Accelerometer was set to disabled!");
/* Get number of sensor-values the sensor will return. Could be
* variable, depending of the amount of axis (1D, 2D or 3D
* accelerometer). */
int sensorValues = Sensors
.getNumSensorValues(Sensors.SENSOR_ACCELEROMETER);
float[] out = new float[sensorValues];
/* Make the OS fill the array we passed. */
Sensors.readSensor(Sensors.SENSOR_ACCELEROMETER, out);
/* And return it. */
return out;
}
}
Application Error: com.neel
An error has occured in com.neel. Unable to
instantiate activity
ComponentInfo{com.neel/com.neel.Accelerometer};
java.lang.InstantiationException:
com.neel.Accelerometer
public class TestLayout extends Activity {
private AccelerometerReader myAcReader = new AccelerometerReader(true);
@Override
public void onCreate(Bundle icicle) {
super.onCreate(icicle);
this.setContentView(R.layout.main);
// Perhaps make a button-OnClick show the Accelerometer-Values in a TextView...
}
}
int sensorValues = Sensors.getNumSensorValues(Sensors.SENSOR_ACCELEROMETER);
float[] out = new float[sensorValues];
/* Make the OS fill the array we passed. */
Sensors.readSensor(Sensors.SENSOR_ACCELEROMETER, out);
/* And return it. */
return out;
Bretters wrote:have you messed with this by putting your application on the Google Phone? I would like to set the google phone to read the accelerometer data and to change configuration based on the No Hand's application my application development class is working on- to where the phone would switch to blue tooth if say the accelerometer tells notifies the system that the phone is going 15+ mph. willing to work in small steps like just being able to read the accelerometer data and put into txt. we do have a google phone to test with and the emulator on the computer.
Users browsing this forum: No registered users and 1 guest