Thanks Erel. That is a start point.You should use PhoneSensors from the Phone library.
Thanks Erel. That is a start point.
I think that a class named "tilt2degrees.bas" or "titlt2angle.bas" would be a good contribution in Basic4android library.
As a beginer I'm not able to do that, i still have a lot to learn.
Maybe somebody more skilled can do it.
thanks
Sub Globals
Dim PO As PhoneOrientation
End Sub
Sub Activity_Create(FirstTime As Boolean)
Dim label1 As Label
label1.Initialize("")
Activity.AddView(label1, 0, 0, 100%x, 100%y)
End Sub
Sub Activity_Resume
PO.StartListening("PO")
End Sub
Sub Activity_Pause
PO.StopListening
End Sub
Sub PO_OrientationChanged(Azimuth As Float, Pitch As Float, Roll As Float)
label1.Text = Azimuth & CRLF & Pitch & CRLF & Roll
End Sub
Thank you LinostarThe PhoneSensors, particularly the orientation sensor from the PhoneSensors, already give you that.
Since it is only the tilt angles you want (i.e. orientation angles), you can use directly a PhoneOrientation object from the Phone library.
Why does it give this error when the app is closed with the back button (I am using Phone library V2.26):The PhoneSensors, particularly the orientation sensor from the PhoneSensors, already give you that.
Since it is only the tilt angles you want (i.e. orientation angles), you can use directly a PhoneOrientation object from the Phone library.
Below an example that shows how to use a PhoneOrientation object:
B4X:Sub Globals Dim PO As PhoneOrientation End Sub Sub Activity_Create(FirstTime As Boolean) Dim label1 As Label label1.Initialize("") Activity.AddView(label1, 0, 0, 100%x, 100%y) End Sub Sub Activity_Resume PO.StartListening("PO") End Sub Sub Activity_Pause PO.StopListening End Sub Sub PO_OrientationChanged(Azimuth As Float, Pitch As Float, Roll As Float) label1.Text = Azimuth & CRLF & Pitch & CRLF & Roll End Sub
Note that Azimuth is the tilt angle in the horizontal plane, Roll is the tilt angle in the vertical plane, and Pitch is the tilt angle between the horizontal and vertical planes.