Android Question Orientation sensor

AlpVir

Well-Known Member
Licensed User
Longtime User

Attachments

  • Screenshot_2015-09-26-10-35-26.jpg
    Screenshot_2015-09-26-10-35-26.jpg
    96.1 KB · Views: 369

AlpVir

Well-Known Member
Licensed User
Longtime User
Always referring to the example
https://www.b4x.com/android/forum/threads/orientation-and-accelerometer.6647/
I modified the sub AddSensor

B4X:
Sub AddSensor(SensorType As Int, Name As String, ThreeValues As Boolean) As SensorData
    Dim sd As SensorData
    sd.Initialize
    sd.Name = Name
    sd.ThreeValues = ThreeValues
    Dim ps As PhoneSensors
    ' ps.Initialize(SensorType)
    ps.Initialize2(SensorType,3)
    SensorsMap.Put(ps, sd)
    Log(Name & " MaxValue = " & ps.MaxValue)
End Sub

Nothing!
 
Upvote 0

AlpVir

Well-Known Member
Licensed User
Longtime User
Upvote 0

AlpVir

Well-Known Member
Licensed User
Longtime User
I confirm that there are (at Google Play) many apps that make use of the orientation sensor. All work perfectly with my smartphone (Asus Zenfone 2).
But no app or piece of code (developed in B4a) works !!!
Is there any way to solve the problem ?
Thank you in advance.
 
Upvote 0

Erel

B4X founder
Staff member
Licensed User
Longtime User
Upvote 0

AlpVir

Well-Known Member
Licensed User
Longtime User
No positive result by changing the following
B4X:
        'AddSensor(ps.TYPE_ORIENTATION, "ORIENTATION", True)
        AddSensor(3, "ORIENTATION", True)
Even addressing the problem with a completely different code
B4X:
Sub Process_Globals
    Dim Sensor As PhoneOrientation
End Sub

Sub Globals
End Sub

Sub Activity_Create(FirstTime As Boolean)
    Sensor.StartListening("sensor")
End Sub

Sub Activity_Resume
    Sensor.StartListening("sensor")
End Sub

Sub Activity_Pause (UserClosed As Boolean)
    Sensor.StopListening
End Sub

Sub sensor_OrientationChanged (Azimuth As Float, Pitch As Float, Roll As Float)
    Log(Azimuth & " " & Pitch & " " &  Roll)
End Sub

It works perfectly with a Motorola Defy Plus (Android 2.3) but not with a Asus Zenfone 2 (Android 5)
 
Upvote 0

AlpVir

Well-Known Member
Licensed User
Longtime User
Replacing "ps.TYPE_ORIENTATION" with "3" I thought of applying the post tip # 10.
Remains alive the question: how to read a value of the orientation sensor?
I also added the line
android.hardware.sensor.orientation = "false"
in the manifest.
I then read later that it too is useless.
I'm trying all ......
I searched the forum various keywords: orientation, sensor, PhoneSensor, etc.
The links are many and I consulted them all.
Nothing !
 
Last edited:
Upvote 0

AlpVir

Well-Known Member
Licensed User
Longtime User
This had already been said in the post #8
Surely it is a problem of my device, but the B4A language can not solve it. Probably because it follows too closely the standards.
Other languages (Java) conversely does not have these problems. The proof is that there are very numerous apps that properly read the orientation sensor.
It is therefore not a hardware but software issue.
For example, the app "Bubble level"
https://play.google.com/store/apps/details?id=net.androgames.level
it works perfectly !
The source of this app is here https://github.com/avianey/Level
https://github.com/avianey/Level
Consulting them who is more experienced than me should understand where you stop the B4A language and propose necessary adjustments. This is to pass a B4A limit for my benefit and all those who own smartphones that do not strictly follow the standards set out in post #14.
Reading for many years the B4A forum I saw that it is possible to insert some Java code line within the B4A code. Perhaps in this case you could do this, but I'm not able. Java does not know.
Thanks in advance for any help on this matter.
 
Upvote 0

AlpVir

Well-Known Member
Licensed User
Longtime User
This is not related to the programming language.
I do not agree. I try to explain why :
1) there are many apps that measure the inclination of a surface on which it must rest smartphone; they are so-called "spirit level" or "bubble level";
2) work correctly on both my smartphone and provide more than reliable results;
3) probably using the sensor "Orientation" and not the "Accelerometer";
4) almost certainly developed in Java.

I found that the same code (which reads the "Orientation" sensor) works perfectly on a Motorola Defy Plus and does not work on an Asus Zenfone 2.
Unless interpret this as due to different version of Android (2.3 and 5.1) it seems to assume it is a software issue of the language used.
Definitely not the hardware.

If, however, you use the "Accelerometer" sensor will have some very big mistakes (even 10-12 degrees) with both devices, and these errors are not constant in the 0-90 degree range that interests me.
To derive the inclination by an accelerometer value I followed some guidelines found on this forum that simply suggested to multiply the Y value for the coefficient of gravity (9.81 ca).
This is not valid for any of the 2 devices. From all this I infer that the "Accelerometer" sensor is not suitable for measuring inclinations and you must use the "Orientation" sensor.
This seems to me only logical given their name and saw that the first analyzes a dynamic and the second a static situation.

Sorry to see that, after many years of good use of B4A language, I must unfortunately note that it has found its limits: it is not operated the important hardware of any particular device.
 
Upvote 0

Erel

B4X founder
Staff member
Licensed User
Longtime User
I will say it again, the programming language is not important. What is important is which API is called.
Also remember that B4A generates Java code which is then compiled to native byte code.

I did check the source code of the app you posted (did you check it?). It uses the accelerometer sensor.

SS-2016-08-16_11.58.37.png


This is my last post in this thread.
 
Upvote 0
Top