Android Tutorial Orientation and accelerometer

The attached program displays the values of the different sensors:

sensors.png


It creates a PhoneSensors object for each type of sensor.
As you can see in the attached code, two Maps are used to hold the phone sensors and the other required data. This way there is no need to write any duplicate code.

A better method for finding the orientation values: https://www.b4x.com/android/forum/threads/orientation-and-accelerometer.6647/page-6#post-476271
 

Attachments

  • SensorsExample.zip
    7.5 KB · Views: 1,792
Last edited:

JonPM

Well-Known Member
Licensed User
Longtime User
I'm trying to figure out a way to detect the device's specific orientation. Not just landscape or portrait, but when it is landscape-normal or landscape-upsidedown, etc. I thought using this example would be easy, but I can't seem to find reliable numbers to detect which way the device is being held. I looked at both Orientation and Accelerometer values, but they vary quite a bit with the tilt of the device in each orientation. Any ideas?
 

sirjo66

Well-Known Member
Licensed User
Longtime User
Hello,

I'm trying to use this example on my Samsung GT-I5800.

If I run "Android Assistant" program, it tell me that "temperature sensor" is supported, but if I run "Sensors" project I see ACCELEROMETER, GYROSCOPE, LIGHT, MAGNETIC, ORIENTATION, PRESSURE and PROXIMITY, but I don't see TEMPERATURE :sign0010:

I am using last version of B4A, with Phone library version 2.00

If the sensor is not supported, why don't appeare "TEMPERATURE is not supported" ??

Don't appeare the line !!

Thanks and sorry for my english

Sergio
 

stu14t

Active Member
Licensed User
Longtime User
I'm attempting to build an app that knows the direction (Compass bearing) you are facing when taking a picture.

Now, when you take a photo the phone is orientated in a different direction (side on). My question is, would I have to use the Z orientation as opposed to the X for the compass bearing?
 

stu14t

Active Member
Licensed User
Longtime User
Erel,

That didn't work. However, I found this on Stack Overflow but I need access to getOrientation and remapCoordinateSystem
 

clewgsm

Member
Licensed User
Longtime User
I'm sorry but I read several discussions about this and didn't find a proper solution that correctly handles different rolls.

Hi Erel,

I'm using the example at Post #1 of this thread. I'm developing some filters for the accelerometer output, but I'm having problems in debugging the code because even if I put a breakpoint on certain line of the code and the IDE breaks on it, it seems that the listening event coutinues to be triggered by the system in background.

I can see the labels that continue to be updated even if the Debugger is stopped at the Breakpoint and the variables where I store the sensor outputs get values that are different from what is currently reported by the SensorChanged event.

It looks to me that the Debugger breakpoint doesn't have any effect on stopping the calling of the phonesensor listener event. :confused:

How can I solve this issue ?

Many thanks in advance !
 

awama

Active Member
Licensed User
Longtime User
Galaxy S4 sensors temperature and humidity

Hi Erel,

The new Samsung Galaxy S4 has sensors for air pressure, temperature and humidity.

In your sensors-example the pressure measurement works well.

B4a also supports temperature sensors, but it is displayed : 'is not supported'
What could be the reason?

It would be nice if b4a could also support humidity sensor. Then we could develop an app for weather station. :)

Many thanks.
 

librettista

Member
Licensed User
Longtime User
I have started using B4A v3.00 and find out that when using the sensors, a lot of periodic single line "true" texts appear in the log, that are not logged by the source code.

It did not happen in v2.70.

If you want to reproduce it, take your sample app, comment out all the “AddSensor” lines except the one for “TYPE_PROXIMITY”.

If you run the app, you could see that each time you put your hand near and then away from the device, a “true” appears in the log. It is logged before entering “Sensor_SensorChanged”. I'm using Galaxy Note II (7100)

If you leave all the “AddSensor” uncommented (or just leave the TYPE_ACCELEROMETER unncomented), you will see a lot of continuous “true”s logged.

I think it could be some call to “Log” left inside your internal libraries and this is the reason of this post: if would you please check it and if it is the case, fix it. It makes the Logs unreadable in my app as they fill up of a LOT of “true”s.

Thanks in advance.
 

Shay

Well-Known Member
Licensed User
Longtime User
Thanks this solve the problem - I was just about sending same question

b.t.w I did not see anywhere, how much battery does the accelometer consume
and is it possible to reduce the reading interval?
 

Shay

Well-Known Member
Licensed User
Longtime User
how canI know if someone is moving (walking to some direction)
I assume I need to check the Linear sensor
B4X:
AddSensor(10, "LINEAR", True)
but what? since even if phone is on the table the numbers is allways changing...
 
Top