I seem to have missed something when it comes to sensor events. As long as it's just the one sensor I'm OK, but despite trimming the sensors example down to it's essence I'm unsure about getting the INT that tells me which sensor fired the event.
Minimalist code (all extraneous stuff such as stopping listening has been removed. Run at your own risk!):
Is it mandatory to use a map & use the whole sensor object as a key in order to identify it?:sign0085:
Minimalist code (all extraneous stuff such as stopping listening has been removed. Run at your own risk!):
B4X:
Sub Process_Globals
End Sub
Sub Globals
End Sub
Sub Activity_Create(FirstTime As Boolean)
If FirstTime Then
Dim ps As PhoneSensors 'This object is only used to access the type constants.
Log("Accel="&ps.TYPE_ACCELEROMETER)
Msgbox(ps.TYPE_ACCELEROMETER,"Accelerometer")
'These appear to return 1 for the Value of TYPE_ACCELEROMETER
ps.Initialize(ps.TYPE_ACCELEROMETER)
'This is basically what happens in the AddSensor Sub in the example program
ps.StartListening("Sensor")
'Starts listening to the accelerometer
End If
End Sub
Sub Activity_Resume
End Sub
Sub Activity_Pause (UserClosed As Boolean)
End Sub
Sub Sensor_SensorChanged (Values() As Float)
Dim ps As PhoneSensors
ps=Sender
'ps has a constant for TYPE_ACCELEROMETER, but how do I read what TYPE the sender is?
Log(Sender)
Msgbox(Sender,ps.TYPE_ACCELEROMETER)
End Sub