android-sensors

Why onSensorChange is not invoked when Wearable device is in Ambient Mode

一个人想着一个人 提交于 2020-01-02 16:26:09
问题 I'm developing a wearable app and I've noticed a strange behaviour. I have a class FooService extends Service implements SensorEventListener and I've override onSensorChanged() method: @Override public void onSensorChanged(SensorEvent sensorEvent) { if (sensorEvent.sensor.getType() != Sensor.TYPE_ACCELEROMETER) { Log.e(TAG, getString(R.string.err_wrong_sensor_registered)); return; } float x = sensorEvent.values[0]; float y = sensorEvent.values[1]; float z = sensorEvent.values[2]; ... } This

Android (big) fail on float values product

大憨熊 提交于 2020-01-01 19:56:33
问题 the situation is drammatic... It's 5 days that i must resolve this problem and i can't get out. The problem: a simple operation as a product make always wrong result. Why? Extract of the code: //all vars are float // resultVec is a vector [3] // Rs is a vector [3] // accelerationvalues is a vector [3] resultVec[0]=Rs[0]*accelerationvalues[0]+Rs[1]*accelerationvalues[1]+Rs[2]*accelerationvalues[2]; //debug to print result Log.d("e", "("+Rs[0]+")*("+accelerationvalues[0]+")+("+Rs[1]+")*("

Android (big) fail on float values product

ε祈祈猫儿з 提交于 2020-01-01 19:56:29
问题 the situation is drammatic... It's 5 days that i must resolve this problem and i can't get out. The problem: a simple operation as a product make always wrong result. Why? Extract of the code: //all vars are float // resultVec is a vector [3] // Rs is a vector [3] // accelerationvalues is a vector [3] resultVec[0]=Rs[0]*accelerationvalues[0]+Rs[1]*accelerationvalues[1]+Rs[2]*accelerationvalues[2]; //debug to print result Log.d("e", "("+Rs[0]+")*("+accelerationvalues[0]+")+("+Rs[1]+")*("

Android : Get the maximum value of light sensor

女生的网名这么多〃 提交于 2020-01-01 12:35:08
问题 For my app I need to get the maximum value of light sensor. I thought it was the same for all devices which have light sensor (ie SensorManager.LIGHT_SUNLIGHT_MAX) but according to sample tests made on devices I was wrong. The problem is that with SensorListener you can only know when the value has changed. So my question is: How to get maximum value of light sensor (assuming that the user can put a powerfull light in front of the sensor that, ie light value > maximum sensor value) ? A

Android Fall detection

蹲街弑〆低调 提交于 2019-12-31 02:09:12
问题 I am implementing the fall detection using accelerometer sensor, and create below code. public void onSensorChanged(SensorEvent foEvent) { if (foEvent.sensor.getType() == Sensor.TYPE_ACCELEROMETER) { double loX = foEvent.values[0]; double loY = foEvent.values[1]; double loZ = foEvent.values[2]; double loAccelerationReader = Math.sqrt(Math.pow(loX, 2) + Math.pow(loY, 2) + Math.pow(loZ, 2)); mlPreviousTime = System.currentTimeMillis(); Log.i(TAG, "loX : " + loX + " loY : " + loY + " loZ : " +

Unregistering SensorManager doesn't work

删除回忆录丶 提交于 2019-12-30 11:12:12
问题 In my app, I am using the light and proximity sensor to detect phone out of pocket functionality and then unregistering the SensorManager when their detection is complete. But even when the CPU usage by the app shows just 1-2 sec usage, the battery usage always shows my app as no. 1 app in the list which is worrying. I have used the SensorManager.unRegisterListener and also set SensorManager = null, but the situation remains the same. I have read, that due to some bug, the sensors are not

Unregistering SensorManager doesn't work

社会主义新天地 提交于 2019-12-30 11:12:04
问题 In my app, I am using the light and proximity sensor to detect phone out of pocket functionality and then unregistering the SensorManager when their detection is complete. But even when the CPU usage by the app shows just 1-2 sec usage, the battery usage always shows my app as no. 1 app in the list which is worrying. I have used the SensorManager.unRegisterListener and also set SensorManager = null, but the situation remains the same. I have read, that due to some bug, the sensors are not

Android - how to make RotateAnimation more smooth and “physical”?

冷暖自知 提交于 2019-12-30 05:35:33
问题 I'm implementing a kind of a "compass arrow" that follows destination depending on physical orientation of the device using magnetic field sensor. Suddenly I faced with a little problem. Obtaining bearing and azimuth is OK, but performing a realistic animation turned into a really hard task. I tried to use different interpolators to make animation more "physical" (i. e. as in real compass, which arrow oscillate after hairpin rotation, accelerate and decelerate during movement etc). Now I'm

How to log data from Android Motion Sensors at a fixed rate

不羁岁月 提交于 2019-12-30 03:09:43
问题 I'm learning the Basics of Android programming. I have a simple android test application in which i log the accelerometer,magnetometer and the orientation data to an external file while also displaying it. I initiate the logging process on click of a Start button (registerListener for relevant sensors) by calling a method initLogger . Which looks something similar to this... public void initLogger(View view) { boolean bFlag = false; Button btnStart = (Button)findViewById(R.id.btnStartLog);

Android: How to use SensorManager.getAltitude(float p0, float p)?

早过忘川 提交于 2019-12-29 06:30:15
问题 I found an alternative way to obtain altitude by using SensorManager but it requires two paramaters. public static float getAltitude (float p0, float p) Computes the Altitude in meters from the atmospheric pressure and the pressure at sea level. p0 pressure at sea level p atmospheric pressure Would you teach us on how to use it by practical example/code snippet. UPDATES1 I found web service provider (WSP) url to obtain the p0 pressure at sea level . I have successfully get the value but don't