Android Question Sensor in Receiver

dibesw

Active Member
Licensed User
Longtime User
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)
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
 

dibesw

Active Member
Licensed User
Longtime User
Grazie per la risposta Alessandro.
In effetti non uso un SERVICE dal momento che il RECEIVER rimane sempre in esecuzione (e lo vedo dal "beep" che ho messo per test);
solo che non risponde più il SENSOR
 
Upvote 0

dibesw

Active Member
Licensed User
Longtime User
do you have a foreground service running in your app?
maybe you need one to keep the app responding.
Grazie per la risposta Alessandro.
In effetti non uso un SERVICE dal momento che il RECEIVER rimane sempre in esecuzione (e lo vedo dal "beep" che ho messo per test);
solo che non risponde più il SENSOR
 
Upvote 0

DonManfred

Expert
Licensed User
Longtime User
Why are you posting the same answer again?

Note that this is the english part of the forum. You should write at least in english here.
 
Upvote 0

dibesw

Active Member
Licensed User
Longtime User
I just wanted to know if anyone has had problems with "Shock Detector" (PhoneSensor) in background mode, i.e., with the app closed.
I've tried everything, both with StartForegroundService and Receiver. Maybe it's a PhoneSensor issue.
 
Upvote 0
Top