Android Question [SOLVED] PhoneSensors.Initialize2 blocks the sensor

lemonisdead

Well-Known Member
Licensed User
Longtime User
Hi,
I am using the TYPE_ACCELEROMETER and have noticed that some devices won't accept Initialize2 values.

For example: I use a service to study the best way to collect the sensor's value. I wanted to check which sensors delay would be the best.
For that I have an EditText feeding the tSpeed and coming from the Main activity. Before each change, I stop my service. Than I restart it.

What I have noticed : the Moto G accepts only one time change of value. It starts at 0 but if I change to 3, the sensor won't send data... While a noname phone accepts many changes of values.
But when the sensor is blocked, it is never considered as defected (MaxValue never reaches -1).

So my question is : does it exist a way to be sure to be able to collect data ? Many thanks

B4X:
Sub Process_Globals
   Dim Sensor As PhoneSensors
End Sub

Sub Service_Create
    Dim tTemp As Int =Main.tSpeed 'this is a Variable charged with values from 0 to 3
    Log("tTemp Value: " & tTemp)
    Sensor.Initialize2(Sensor.TYPE_ACCELEROMETER,tTemp)
End Sub

Sub Service_Start
    Sensor.StartListening("sensor")
    if Sensor.MaxValue=-1 Then Log("Sensor not working")
End Sub

Sub Service_Destroy
    Sensor.StopListening
    Log("Service stopped")
End Sub

Sub sensor_SensorChanged (Values() As Float)
     Log(Values())
End Sub
 

lemonisdead

Well-Known Member
Licensed User
Longtime User
Well, it's odd : I have seen in the unfiltered logs that, when you call StopListening it won't stop the sensor but prints a lot of

ignoring event: sensor_sensorchanged

even if the app is closed. In my opinion, it is missing a way to release the sensor.
 
Upvote 0

lemonisdead

Well-Known Member
Licensed User
Longtime User
Hi Erel,
Well, I am sure the service is not started multiple times (I wait to see the Service_Destroy in the logs tab before to restart it).
As you have suggested, I had already tried to move the StartListening to Service_Create and the behaviour is the same.

But this only appears with the Moto G. And when using Initialize instead of Initialize2, when I stop the service, the sensor is stopped too.

So, I will use Initialize only and use a timer instead to create a manageable delay.

Many thanks :)
 
Upvote 0
Top