Android Question PhoneSensors Android 6 support

chrjak

Active Member
Licensed User
Longtime User
Hey community,

I am noticing a problem on android 6+ devices. The PhoneSensors don't show correct values. It is only "0" all the time when i try to get the altitude value.

Code:

Dim ps as phonesensors
ps.Initialize(ps.TYPE_PRESSURE)
ps.StartListening("PS")

Sub PS_SensorChanged(SensorValues() As Float)
Log(SensorValues(1))
end sub

On other android versions it works. e.g. Android 5

Maybe I have to ask for permission. But how do I do this?

Update: HPA works. But not altitude
 
Last edited:

chrjak

Active Member
Licensed User
Longtime User
If sensor is not supported why do I get Hpa values? (Sensorvalues(0))

And it is supported for sure:
- LG G4
- Samsung Galaxy S7 Edge
 
Upvote 0

chrjak

Active Member
Licensed User
Longtime User
Sorry for pushing but i don't manage to solve this bug. I don't know why this is happening but e.g. the samsung managing app (Enter in your phone pad: *#0*# and click on sensor) it works. And yes the sensor is supported

Note: The bug is only on Android 6+ Please help me
 
Upvote 0

lemonisdead

Well-Known Member
Licensed User
Longtime User
Upvote 0

chrjak

Active Member
Licensed User
Longtime User
hmmm... i've tested it myself without documentation and on phones with android lower than 6 it is like:
SensorValues(0) = HPA
SensorValues(1) = Altitude in Meters
SensorValues(2) = something else...
SensorValues(3) = Error

But thats interesting... I have to check that
 
Upvote 0

chrjak

Active Member
Licensed User
Longtime User
I will try that tomorrow. I've made a little demonstration project for you:

B4X:
Sub Activity_Create(FirstTime As Boolean)
    'Do not forget to load the layout file created with the visual designer. For example:
    Dim ps As PhoneSensors
    ps.Initialize(ps.TYPE_PRESSURE)
    ps.StartListening("PS")
End Sub

Sub Activity_Resume

End Sub

Sub Activity_Pause (UserClosed As Boolean)

End Sub

Sub PS_SensorChanged(SensorValues() As Float)
    Dim textstring As String
    For i = 0 To SensorValues.Length -1
        textstring = textstring & SensorValues(i) & CRLF
    Next
    ToastMessageShow(textstring, True)
End Sub

Running this project on my galaxy s4 running android 5 lollipop looks like that:
https://www.dropbox.com/s/0xuj8kfdla4mg92/Screenshot_2016-04-06-20-24-08.png?dl=0

As you see my listing above is correct... I will launch this now on the s7 edge and let's see what it returns
 
Upvote 0

chrjak

Active Member
Licensed User
Longtime User
Alright. On Android 6 it looks like:

920.80(.....)
0
0

Sooooo... I don't get the problem but i ll try the other library. as you see you've got at least the hpa
 
Upvote 0

chrjak

Active Member
Licensed User
Longtime User
I tested now with PhoneSensorExtra and i get the same result as above:

921.973(...)
0
0

Please help :(
 
Upvote 0
Top