android-sensors

Android SensorManager.getOrientation() returns pitch between -PI/2 and PI/2

大兔子大兔子 提交于 2019-12-01 11:41:30
I am designing an app that needs to check the device's orientation (Azimuth, Pitch and Roll). I use the following code to achieve this: @Override public void onSensorChanged(SensorEvent event) { if(event.sensor.getType() == Sensor.TYPE_ACCELEROMETER) gravityMatrix = event.values.clone();// Fill gravityMatrix with accelerometer values else if(event.sensor.getType() == Sensor.TYPE_MAGNETIC_FIELD) geomagneticMatrix = event.values.clone();// Fill geomagneticMatrix with magnetic-field sensor values if(gravityMatrix != null && geomagneticMatrix != null){ RMatrix = new float[16]; IMatrix = new float

Multiple sensors on an android application

断了今生、忘了曾经 提交于 2019-12-01 11:31:00
问题 I am currently developing an android application that uses multiple sensors, I have used mSensor= mySensorManager.getDefaultSensor(Sensor.TYPE_ACCELEROMETER); in OnCreate Method to get the sensor and tv.setText("X: "+ sensorEvent.values[0] + ...); in onSensorChanged method, to display the accelerometer values in a text view. How can I add more sensors and display their values in the same way? How will the program know which sensor I am referring to when I say sensorEvent.values[0] ? Thank you

Unregistering SensorManager doesn't work

强颜欢笑 提交于 2019-12-01 11:17:33
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 unregistered correctly. Any good way to dispose the sensors correctly ? Pls guide. Omkar Ghaisas Updated

Android SensorManager.getOrientation() returns pitch between -PI/2 and PI/2

无人久伴 提交于 2019-12-01 09:45:49
问题 I am designing an app that needs to check the device's orientation (Azimuth, Pitch and Roll). I use the following code to achieve this: @Override public void onSensorChanged(SensorEvent event) { if(event.sensor.getType() == Sensor.TYPE_ACCELEROMETER) gravityMatrix = event.values.clone();// Fill gravityMatrix with accelerometer values else if(event.sensor.getType() == Sensor.TYPE_MAGNETIC_FIELD) geomagneticMatrix = event.values.clone();// Fill geomagneticMatrix with magnetic-field sensor

detect Shake in android

此生再无相见时 提交于 2019-12-01 09:18:52
I am trying to hit an API when user shake a device 10 times. I have tried many git sample and stack overflow solution but non of them did solve my problem. Some of them detecting shake before 10 times or after 10 times. I have tried Seiamic and ShakeDetector libraries. Please give me some valuable solution. I have done that using this library : 1) Add the dependecy in your build.gridle file allprojects { repositories { ... maven { url 'https://jitpack.io' } } } dependencies { compile 'com.github.safetysystemtechnology:android-shake-detector:v1.2' } 2) Give the permission to your app manifest

detect Shake in android

老子叫甜甜 提交于 2019-12-01 06:49:14
问题 I am trying to hit an API when user shake a device 10 times. I have tried many git sample and stack overflow solution but non of them did solve my problem. Some of them detecting shake before 10 times or after 10 times. I have tried Seiamic and ShakeDetector libraries. Please give me some valuable solution. 回答1: I have done that using this library : 1) Add the dependecy in your build.gridle file allprojects { repositories { ... maven { url 'https://jitpack.io' } } } dependencies { compile

Is it possible to detect motion when screen is off?

心已入冬 提交于 2019-12-01 06:07:06
My app simply need to detect any motion of the device while screen is off. I know that accelerometer is used for this task but it don't work while screen is off in all devices. this is a list of devices http://www.saltwebsites.com/2012/android-accelerometers-screen-off so is there a way of taking accelerometer sensor data while screen is off that works on all devices? or is there a way to detect motion using another sensors? Partial Wake Lock is all you need to access accelerometer readings while the screen is off. You can use it like this: private PowerManager.WakeLock mWakeLock; PowerManager

Step counter doesn't reset the step count

爷,独闯天下 提交于 2019-12-01 05:45:34
I am able to start and stop recording steps with the Sensor.TYPE_STEP_COUNTER by registering and unregistering the listener. However, the actual value that is passed to my app via the SensorEvent object does not reset to zero when the application is destroyed. If I close the app and restart it, or even if I recompile my app with updates, the counter picks up where it left off. If I run other apps that use the step counter sensor, they independently count their steps and reset their counter. Does the sensor have a cache that is app specific? What is the correct way to reset the sensor to zero

android: why getrotationmatrix return false?

泄露秘密 提交于 2019-12-01 05:32:36
I want to get the orientation of my phone and I have using this code that I find lot of people using it. this is the code public void onSensorChanged(SensorEvent event) { //if the data sensor is unreliabel if(event.accuracy == SensorManager.SENSOR_STATUS_UNRELIABLE) return; //gets the value switch (event.sensor.getType()) { case Sensor.TYPE_ACCELEROMETER: gravity = event.values.clone(); break; case Sensor.TYPE_MAGNETIC_FIELD: geomag = event.values.clone(); break; } getOrientation(); } private void getOrientation(){ //if gravity n geomag have value, find the rotation matrix if(gravity != null &

Step counter doesn't reset the step count

笑着哭i 提交于 2019-12-01 02:40:38
问题 I am able to start and stop recording steps with the Sensor.TYPE_STEP_COUNTER by registering and unregistering the listener. However, the actual value that is passed to my app via the SensorEvent object does not reset to zero when the application is destroyed. If I close the app and restart it, or even if I recompile my app with updates, the counter picks up where it left off. If I run other apps that use the step counter sensor, they independently count their steps and reset their counter.