android-sensors

Sensor simulator's NetworkOnMainThreadException

允我心安 提交于 2019-12-07 23:43:17
问题 I followed this instruction to debug my app on emulator using sensor simulator: http://code.google.com/p/openintents/wiki/SensorSimulator#How_to_use_the_in_your_application I completed all steps above, but in my case everything was not as simple as described in instructions. I got NetworkOnMainThreadException trying to connect, register listener etc. So I created async task to solve this problem. Now, I have the following: connection to simulator: @Override public void onCreate(Bundle

Blue flash light (Arc) on Google Maps

China☆狼群 提交于 2019-12-07 14:47:31
问题 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? 回答1: 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() =

Direction using sensor

倖福魔咒の 提交于 2019-12-07 11:17:52
问题 In my app i wanted to show device direction such as north, south, east, west. For that i am using accelerometer and magnetic sensor and tried with following code. public class MainActivity extends Activity implements SensorEventListener { public static float swRoll; public static float swPitch; public static float swAzimuth; public static SensorManager mSensorManager; public static Sensor accelerometer; public static Sensor magnetometer; public static float[] mAccelerometer = null; public

How to make a copy of the Android Sensor SensorEvent Object

杀马特。学长 韩版系。学妹 提交于 2019-12-07 08:23:33
I have a sparesArray which I use to store & batch SensorEvents by holding onto each sensor typeId and SensorEvent object until a timer fires. SparseArray<SensorEvent> sensorEventMap = new SparseArray<SensorEvent>(); public void onSensorChanged(SensorEvent event) { synchronized (this) { sensorEventMap.put(event.sensor.getType(), event); } } I am having issues where the SensorEvent is getting overwritten in the array before my timer fires, so I'd like to make a copy of the SensorEvent and store the copy in the array instead. How can I make a copy of SensorEvent ? I need the whole SensorEvent,

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

ぃ、小莉子 提交于 2019-12-07 05:15:30
问题 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? 回答1: I'm aware of a typo error by Google that

“Custom” sensor event rates don't seem to work with SensorManager.registerListener(SensorEventListener listener, Sensor sensor, int rate)

对着背影说爱祢 提交于 2019-12-07 02:02:38
问题 UPDATED: I was able to solve the specific problem I was having by introducing a class-scope static counter and just ignoring ever x number of events. But I'd still like to know what I'm doing wrong re: registering the listener with a hint in microseconds instead of using one of the four given constants. An Activity in my app is engaging the sensors to obtain the orientation of the device, determine the roll, and utilize it. I am using SensorManager.registerListener(SensorEventListener

How to enable proximity sensor in android

☆樱花仙子☆ 提交于 2019-12-06 15:41:11
I have configured proximeter successfully in my code. Now I want to turn off & on screen programmatically. Code of sensor is working just fine and following method is also getting called. @Override public void onSensorChanged(SensorEvent event) { // TODO Auto-generated method stub PowerManager pm = (PowerManager) getSystemService(Context.POWER_SERVICE); WakeLock screenWakeLock = pm.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK,"screenWakeLock"); if (event.values[0] == 0) { screenWakeLock.acquire(); Log.e("onSensorChanged","NEAR"); } else { if (screenWakeLock != null) { if(screenWakeLock.isHeld())

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

强颜欢笑 提交于 2019-12-06 13:56:30
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 service is started from FooActivity extends WearableActivity - here i override onEnterAmbient() ,

Not able to translate device co-ordinate system to world co-ordinate system on android

一世执手 提交于 2019-12-06 13:15:42
I have written a small code to convert the device co-ordinates into world co-ordinates by multiplying the Rotation matrix(using getRotationMatrix) and the vector (Ax,Ay,Az) which are the accelerometer values. When I run this, and the phone is static, I get a very fluctuating value for the Z axis(from 9.3 to 10.3) and the other two are 0. However when I give the phone some acceleration in any direction , it still doesn't show any change to those values and they remain zero. This is the part of the code where I get the values. if(ctp.getType()==Sensor.TYPE_ACCELEROMETER){ Ca[0]=event.values[0];

How to play with devices like accelerometer and camera using C/C++?

怎甘沉沦 提交于 2019-12-06 11:49:20
问题 As you can see in architecture diagram below android platform has been built using different layers. Application are developed in Java Application Framework is written using Java (according to my understanding) Libraries are in C/C++ For some insane reason I have to play/deal with devices like accelerometer , compass and camera using C/C++ which means directly accessing them in 3rd layer i.e. Libraries . According to my understanding the Application Framework itself would be consuming