android-sensors

android - detect downward acceleration, specifically an elevator

混江龙づ霸主 提交于 2019-12-06 10:31:11
问题 I want to be able to detect a situation where the phone has an acceleration towards the ground (probably means that the Gravity sensor has to be used here also). I have read a lot about this topic in the Android docs, about High and Low pass filters and other posts, and right now what I have is a code sample that gets the acceleration in the X, Y and Z axis after stripping the gravity: if (event.sensor.getType() == Sensor.TYPE_ACCELEROMETER) { final float alpha = (float) 0.8; gravity[0] =

Get Euler Yaw angle of an Android Device

余生长醉 提交于 2019-12-06 09:32:07
问题 I'm trying to get yaw of an android device expressed in euler angles. To be clear i dont want 'Azimuth' (which is the angle to magnetic north) I want the rotation of the 'z' axis of an android device as shown in this picture. This (IMHO) should be the axis used in some car games to determine the amount of steering. It is my understanding I could just use the Accelerometer values (without the magnetic fields) but I'm unable to get the determined value. (probably due to a lack of understanding

Proximity sensor accuracy

江枫思渺然 提交于 2019-12-06 07:41:06
问题 I'm testing the proximity sensor with this code: final SensorManager sensorManager = (SensorManager) getSystemService(SENSOR_SERVICE); final Sensor proximitySensor = sensorManager.getDefaultSensor(Sensor.TYPE_PROXIMITY); sensorManager.registerListener(this, proximitySensor, SensorManager.SENSOR_DELAY_FASTEST); And I'm getting only 5.0 value when my hand is far away from the sensor and 0.0 when it's completely closed the sensor. (I'm testing on Nexus S, 4.1) Can I get the values between 0 and

Android Sensor.TYPE_ORIENTATION works perfect and I can't get the same results with accelerometer and magnetometer

被刻印的时光 ゝ 提交于 2019-12-06 07:17:15
I am trying to use this non-deprecated version of code to get orientation. However I can't get it to work as smooth and perfect as if I just use the deprecated Sensor.TYPE_ORIENTATION. Am I missing something? //OLD @Override public void onSensorChanged(SensorEvent arg0) { m_lastYaw = arg0.values[0]; invalidate(); } //NEW @Override public void onSensorChanged(SensorEvent event) { if (event.accuracy == SensorManager.SENSOR_STATUS_UNRELIABLE){ return; } if (event.sensor.getType() == Sensor.TYPE_ACCELEROMETER) { System.arraycopy(event.values, 0, m_lastAccels, 0, 3); } if (event.sensor.getType() ==

Sensor.TYPE_STEP_DETECTOR not found on android Lollipop

99封情书 提交于 2019-12-06 04:11:57
问题 I am developing a pedometer android application and for that i used Sensor.TYPE_STEP_DETECTOR which is available from android KitKat. Everything was working fine at Nexus 5 and Samsung Alpha but then i tested my application on Moto G(Lollipop) and Nexus 4(Lollipop), both the device are returning null when i am trying to get sensor of Sensor.TYPE_STEP_DETECTOR type. Here is my code: private boolean checkSensorAvailability() { SensorManager sensorManager = (SensorManager) getActivity()

How to get the compass direction from azimuth on Android

生来就可爱ヽ(ⅴ<●) 提交于 2019-12-06 01:46:13
问题 I have to display which direction the user is pointing the Android device. I am using Sensor.TYPE_ACCELEROMETER , Sensor.TYPE_MAGNETIC_FIELD to get the azimuth, pitch, roll. But I am to able to figure out how to get directions (North, south, east , west,...) from this. Please help Thanks 回答1: To point the north you can calculate a rotation in degrees : float rotation = -azimut * 360 / (2 * 3.14159f); You can see the following compass example which make uses of accelerometer and magnetic field

Using TYPE_STEP_COUNTER in a background service?

徘徊边缘 提交于 2019-12-06 00:23:41
问题 I'm looking at implementing the step sensor API introduced in Android 4.4 (http://youtu.be/yv9jskPvLUc). However, I am unable to find a clear explanation on what the recommended way to monitor this in the background is? It seems like most examples only show how to do this with an activity while the app is running. I don't particularly need a high frequency of updates - I basically want to log the amount of steps the user has walked every hour to a backend service. Should I just spin up a

Blue flash light (Arc) on Google Maps

倖福魔咒の 提交于 2019-12-05 21:59:50
Is there any way to have access to the blue flash light appears on google map? I have read in different forums that this blue arc is representative of the reliability of the magnet sensor, is there any way to have access to it in android? I went through Android SDK for magnet outputs. I have found one method that measure the accuracy of magnet based direction of movement. Have you seen following method? @Override public void onAccuracyChanged(Sensor sensor, int i) { if(sensor.getType() == Sensor.TYPE_MAGNETIC_FIELD){ } } This outputs the accuracy in 4 levels for magnet based heading estimation

Android rotation vector sensor error [closed]

流过昼夜 提交于 2019-12-05 13:35:42
I'm not asking a question. I'm going to post this in case anyone else runs into this problem. If you follow the Android API guide for the rotation sensor, you will run into an error. Specifically: java.lang.IllegalArgumentException, because some devices return an array with FIVE values. You can probably fix this now that you know this, but anyway here's how to do it: private int rotateVectLength; private float[] jRotateVectValues = null; public void onSensorChanged(SensorEvent event) { // we received a sensor event. it is a good practice to check // that we received the proper event if (event

android:screenOrientation=“sensorPortrait” doesn't work on API +17

混江龙づ霸主 提交于 2019-12-05 11:27:00
I want my application to work in Portrait & reversePortrait mode .. In other words, I want it to work in portrait and make it rotatable 180 degrees! I'm using the following code within <activity> tag of the MainActivity in the Manifest. android:screenOrientation="sensorPortrait" However, this seems to work only on Android 4.1.2 and backward. It doesn't work on Android 4.2.2 and above! I tried on different phones, the same result! How to solve it? I'm aware of a typo error by Google that replaced sensorPortrait by sensorPortait at some point. Not sure if that is your case, but depending on your