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,591
Last edited:

Mitesh_Shah

Member
Licensed User
Longtime User
HI i am new in b4a. i need some help to put ACCELEROMETER data (X,Y,Z) into some text box and SeekBar

thanks
 

dossa

New Member
Hello.
i need to give only accelerometer data(z) in variable. Can you help me?
Sorry for my english.
thanks
 

JordiCP

Expert
Licensed User
Longtime User
Hi all,

I want my app to decide when to be drawn in portrait or landscape mode, or reverse ones. Based on the X,Y sensors, it seems to be easy to know when it has rotated.

For instance, in a phone I get theses values (aprox)

portrait: X=0 Y=9.8
lanscape: X=9.8 Y=0 (rotating 90º left from portrait)

when running on a tablet, I have,

landscape: X=0 Y=9.8
portrait: X=9.8 Y=0

So sensors info is not enough for me to decide when to draw in landscape or portrait, since X,Y assignments seem to be related to the device default orientation. How can I decide how these values are related to the actual screen orientation?

(One possible approach would be trying to "guess" default screen orientation based on device type and screen size, but I am sure this will not work always.)

----------EDIT------------------------
Have just found LibDisplay tutorial from joseluis

http://www.b4x.com/android/forum/threads/libdisplay-module.14111/#post79879

So I assume that accelerometer sensor information is related to the default screen.

Thanks.
 
Last edited:

JordiCP

Expert
Licensed User
Longtime User
Why don't you let Android take care of that?

You can set the #SupportedOrientations value to fullSensor.

Thank you for pointing this, Erel

There are two reasons for doing it this way

  1. My app uses the camera and only want the device to rotate under certain situations. For instance, not rotate accidentally when taking the photo, and let the user rotate freely when editing it
  2. In some devices, I still have a problem each time I rotate, memory gets lower till it crashes as stated here. So I want the user to start the app in the orientation he chooses, but blocking rotation afterwards.

I would prefer only to control it only for reason 1, but the second is also there
 

Scooter Willis

Member
Licensed User
Longtime User
Hi Erel,
The problem still persists. FYI: every True is preceeded by a line in the log file that states: "Ignoring event: sensor_sensorchanged". After releasing or debugging the app, the TRUE's keep coming, even if I stop the app and remove it from my Android (while leaving B4A running)! Deleting everything that involves the sensors in the sourcecode does not help either. It looks almost as if B4A has started another app or service, but there are no services in my app.
Please help. I am now trying to add In-App billing but the True's make it impossible to debug.

UPDATE: The problem is now solved. This was done by closing one of my other apps which starts up automatically when the Android is switched on (using a Service). Strangely enough this app, even though it should be in activity_pause condition, apparently reports the status of its sensors to B4A while I am working on another app! Any idea about the cause?
Could this be some kind of memory leak?

I have the same repeated output of true problem when beginning to listen to sensor value for barometric pressure. Using v3.0 with 2.2 phone library.
 

Ashley

Member
Licensed User
Longtime User
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.
Hi Erel, I'm trying to get the exact direction in degrees the phone is facing. The position variables (x,y,z) seems to give errors in some directions. Is there any code that combines the relevant sensors to get the AHRS?.
Thanks
Ashley
 

apty

Active Member
Licensed User
Longtime User
how can i run a service that displays x,y,z values of the sensor (accelerometer only)? i.e instead of activity module, i make it service module
 

flightnet

Member
Licensed User
Longtime User
Hey,
I have an additional question, how can I find the g. If I propebly swing the phone so that it Shows me how meny g are given in this Moment.
 
Top