Android Tutorial Android shake event with PhoneSensors

Beja

Expert
Licensed User
Longtime User
If you read carefully Erel's post you could see that he chooses to use the X value only. If you want to handle all values you'll have to pass them too

Thanks lemonisdead,
That was it.
 

Beja

Expert
Licensed User
Longtime User
@eps
Thanks eps.. Erel responded to the X variable only, and that's why all other directions didn't work.
I overlooked this and lemonisdead pointed me to it.
 

ilan

Expert
Licensed User
Longtime User
is it possible to listen to the shake event from a service?
would like to turn on my screen when the phone is locked
 

MiguelAlvarez

Member
Licensed User
Longtime User
The same code will work from a service.
Using from a service in Main
Sub sensor_SensorChanged (Values() As Float)
Shake.HandleSensorEvent(Values)
End Sub
got the :
Error description: Unknown member: handlesensorevent
Occurred on line: 109
Shake.HandleSensorEvent(Values)
Word: handlesensorevent
 

cambopad

Active Member
Licensed User
Longtime User
If I use this in a service that run for a very long time, will it affect the phone performance and battery????
 

stanks

Active Member
Licensed User
Longtime User
when sound is off nothing happens...S3 I9300
i noticed one other big problem. shaking kills my device UI and slow it a lot. restarting ui does not have any effect. i have to flash again ROM!. running apps is ok.
anyone have problems with that?

thanks
 

rtek1000

Active Member
Licensed User
Longtime User
The problem is of course to decide if the stream of values represents a shake.

TYPE_LINEAR_ACCELERATION
added in API level 9
int TYPE_LINEAR_ACCELERATION
A constant describing a linear acceleration sensor type.

See SensorEvent.values for more details.

Constant Value: 10 (0x0000000a)

It may be simpler to check a shake with this data type (TYPE_LINEAR_ACCELERATION).

Source: https://developer.android.com/reference/android/hardware/Sensor?hl=fr#TYPE_LINEAR_ACCELERATION

B4X:
sensor.Initialize(10) ' 10: TYPE_LINEAR_ACCELERATION
 
Cookies are required to use this site. You must accept them to continue using the site. Learn more…