I put a sensor in a Receiver that detects phone motion; it works fine when the app is active, but when it's in the background, it doesn't detect motion.
Without freaking out, does SensorChanged also work in the background?
The receiver starts fine (I tried to set a beep)
Without freaking out, does SensorChanged also work in the background?
The receiver starts fine (I tried to set a beep)
Receiver:
Sub Process_Globals
Dim sensor As PhoneSensors
Dim valopic As Int
Dim manager As PreferenceManager
End Sub
'Called when an intent is received.
'Do not assume that anything else, including the starter service, has run before this method.
Private Sub Receiver_Receive (FirstTime As Boolean, StartingIntent As Intent)
'If FirstTime Then
sensor.Initialize(sensor.TYPE_ACCELEROMETER)
sensor.StartListening("sensor")
'End If
'Dim B As Beeper
'B.Initialize(400,500)
'B.Beep
'Sleep(500)
'B.Release
StartReceiverAt(Me, DateTime.Now + (10 * 1000), True)
End Sub
Sub sensor_SensorChanged (Values() As Float)
HandleSensorEvent(Values)
End Sub
Sub HandleSensorEvent(values() As Float)
valopic=Round(Abs(values(0)))
If valopic = 0 Then Return
'ToastMessageShow(valopic,False)
If manager.GetString("sensib")="Alta" And valopic<10 Then Return
If manager.GetString("sensib")="Media" And valopic<15 Then Return
If manager.GetString("sensib")="Bassa" And valopic<20 Then Return
ShakeEvent
End Sub
Sub ShakeEvent
If manager.GetBoolean("muovi") =True Then
premi
End If
End Sub
Sub premi
If manager.GetString("nome") ="Ciao sono XXX e mi trovo in difficoltà" Then
Msgbox("Indicare il tuo messaggio da inviare in configurazione","")
Return
End If
If manager.GetString("telefono1") ="" Then
Msgbox("Indicare almeno un numero di telefono in configurazione","")
Return
End If
StartActivity(Main2)
End Sub