Hi,
I am facing a problem with accelerometer notification. Basically i'm playing an
audio file when there is a device movement or shaken. First time, when i start
playing an audio file by shaking or moving the device, it is working fine. It
starts playing it from the start. After that when the device is in idle state,
it shouldn't do anything with the audio file play. But due to higher sound
volume audio file play, i'm getting accelerometer notificaion even when really
there is no device movement or shake. Due to this, playing higher volume sound
file, restarting the audio file again and again after few seconds automatically.
So how to resolve of ignoring the unexpected accelerometer notification arrival
when we play higher sound volume audio file.
Note: This issue is happening only when i play higher sound volume audio file.
When i play a lower volume or no volume audio file, i don't observe any
unexpected accelerometer notification. My sample code snippet is below:
Registering events first on application launch:
sensorMgr = (SensorManager) getSystemService(SENSOR_SERVICE);
boolean accelSupported = sensorMgr.registerListener(this,
SensorManager.SENSOR_ACCELEROMETER,
SensorManager.SENSOR_DELAY_UI );
if (!accelSupported) {
// on accelerometer on this device
sensorMgr.unregisterListener( this,
SensorManager.SENSOR_ACCELEROMETER);
}
Accelerometer access code:
public void onSensorChanged(int sensor, float[] values) {
if (sensor == SensorManager.SENSOR_ACCELEROMETER) {
long curTime = System.currentTimeMillis();
// only allow one update every 100ms.
if ((curTime - lastUpdate) > 100) {
long diffTime = (curTime - lastUpdate);
lastUpdate = curTime;
x = values[SensorManager.DATA_X];
y = values[SensorManager.DATA_Y];
z = values[SensorManager.DATA_Z];
float speed = Math.abs(x+y+z - last_x - last_y - last_z) / diffTime
* 10000;
if (speed > SHAKE_THRESHOLD) { // SHAKE_THRESHOLD=300
PlayAudio()
}
If anyone faced this issue, please provide your suggestions to resolve it.
thanks.
-Martin Prabakar.
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google
Groups "Android Beginners" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/android-beginners?hl=en
-~----------~----~----~----~------~----~------~--~---