Android Question Orientation - On Android 6 it works, on Android 11 it doesn't

amorosik

Expert
Licensed User
On Android 6 it works, on Android 11 it doesn't
I am trying this code to display compass, pitch and roll directions
Loaded on phone with Android 6 it works fine
If I try to load on the Eda52 terminal that is equipped with Android 11 as standard, it does not work in the sense that the triple of values rsults always zero
What can it depend on?

Library: Animation, Core, Phone
B4A: ver 11.80 (64 bit)

Main code:
#Region  Project Attributes
    #ApplicationLabel: COMPASS TEST 2
    #VersionCode: 1
    #VersionName:
    'SupportedOrientations possible values: unspecified, landscape or portrait.
    #SupportedOrientations: unspecified
    #CanInstallToExternalStorage: False
    #BridgeLogger:true 
#End Region

#Region  Activity Attributes
    #FullScreen: False
    #IncludeTitle: True
#End Region

Sub Process_Globals
    Dim Orientation As PhoneOrientation
    Dim tmrUpdater As Timer
End Sub

Sub Globals
    Dim pnlRose As Panel
    Dim pnlNeedle As Panel

    Dim Rotation As Animation
    Dim dblAngle As Double
    Dim dblPitch As Double
    Dim dblRoll As Double
  
    Private lblGradi As Label
    Private lblGradi2 As Label
    Private lblGradi3 As Label
    Private lblPitch As Label
    Private lblRoll As Label
End Sub

Sub Activity_Create(FirstTime As Boolean)
    Activity.LoadLayout("Compass")
    pnlRose.SetBackgroundImage(LoadBitmapSample(File.DirAssets, "compass.png", pnlRose.Width, pnlRose.Width))
    pnlNeedle.SetBackgroundImage(LoadBitmapSample(File.DirAssets, "needle.png", pnlRose.Width/9.6, pnlRose.Width))
    Rotation.InitializeRotateCenter("Animation", dblAngle, dblAngle, pnlNeedle)
    Rotation.Duration = 20000
    tmrUpdater.Initialize("tmrUpdater",500)
    Orientation.StartListening("Orientation")
    tmrUpdater.Enabled = True
End Sub

Sub Orientation_OrientationChanged (Azimuth As Float, Pitch As Float, Roll As Float)
    dblAngle = -Azimuth
    dblPitch=Pitch
    dblRoll=Roll
End Sub

Sub tmrUpdater_Tick
    Log("Angolo = " & dblAngle & "  Pitch=" & dblPitch & "  Roll=" & dblRoll)
    Rotation.InitializeRotateCenter("Animation", dblAngle, dblAngle, pnlNeedle)
    Rotation.Duration = 20000
    Rotation.Start(pnlNeedle)
  
    lblGradi.Text=dblAngle
    lblGradi2.Text=NumberFormat2(dblAngle, 3, 2, 2, False)
    lblGradi3.Text=NumberFormat2(dblAngle,3, 0, 2, False)
    lblPitch.Text=NumberFormat2(dblPitch,2, 2, 2, False)
    lblRoll.Text=NumberFormat2(dblRoll,2, 2, 2, False)
End Sub

Log windows:
Logger connesso a:  Honeywell EDA52
--------- beginning of main
** Activity (main) Pause, UserClosed = false **
--------- beginning of crash
anywheresoftware.b4a.B4AUncaughtException
    at anywheresoftware.b4a.Msgbox.debugWait(Msgbox.java:210)
    at anywheresoftware.b4a.debug.Debug.wait(Debug.java:217)
    at anywheresoftware.b4a.debug.Debug.StartFromShell(Debug.java:109)
    at anywheresoftware.b4a.shell.Shell.start(Shell.java:101)
    at anywheresoftware.b4a.ShellBA.raiseEvent2(ShellBA.java:94)
    at aaa.compass2.logicd.main.afterFirstLayout(main.java:97)
    at aaa.compass2.logicd.main.access$000(main.java:17)
    at aaa.compass2.logicd.main$WaitForLayout.run(main.java:83)
    at android.os.Handler.handleCallback(Handler.java:938)
    at android.os.Handler.dispatchMessage(Handler.java:99)
    at android.os.Looper.loop(Looper.java:223)
    at android.app.ActivityThread.main(ActivityThread.java:7697)
    at java.lang.reflect.Method.invoke(Native Method)
    at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:592)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:952)
Copying updated assets files (3)
** Activity (main) Create, isFirst = true **
** Activity (main) Resume **
Angolo = 0  Pitch=0  Roll=0
Angolo = 0  Pitch=0  Roll=0
Angolo = 0  Pitch=0  Roll=0
Angolo = 0  Pitch=0  Roll=0
Angolo = 0  Pitch=0  Roll=0
Angolo = 0  Pitch=0  Roll=0
Angolo = 0  Pitch=0  Roll=0
Angolo = 0  Pitch=0  Roll=0
Angolo = 0  Pitch=0  Roll=0
Angolo = 0  Pitch=0  Roll=0
Angolo = 0  Pitch=0  Roll=0
 
Last edited:

agraham

Expert
Licensed User
Longtime User
Most probably the terminal does not have a compass chip.
 
Upvote 0

amorosik

Expert
Licensed User
Yes, on my Eda52 with Erel sensor test, the ORIENTATION 'is not supported'
But we are now try on Xiaomi 10 pro, and also on this device ORIENTATION seem not supported...

aaa_xiaomi_10_pro_1.jpg


... BUT with his compass app, it's all ok, like visible on the image
Then his compass app is not based on ORIENTATION value
On wich sensor/value is based?

aaa_xiaomi_10_pro_2.jpg
 
Upvote 0

amorosik

Expert
Licensed User
A compass indicates the direction of the earth magnetic field. A compass needle is a magnet. Smartphones use a three-axis magnetometer Hall effect sensor to detect magnetic fields.

Sure, but no one of the three values from MAGNETIC seem to show the degree from north pole
There is a trick to use the three values and obtain a 0-360 degree?
 
Upvote 0

agraham

Expert
Licensed User
Longtime User
The compass direction is resolved from the orientation and magnetic sensors, or the accelerometer and magnetic sensors if the device has no orientation sensor.

Here's a class I wrote following Googles recommendation for devices without an orientation sensor, but it is very basic and doesn't work very well. It probably needs better filtering or smoothing of the sensor readings but I didn't persevere with it as
 

Attachments

  • Compass.bas
    2.2 KB · Views: 85
Upvote 0
Top