Android 怎么获得手机即时的重力感应的X,Y,Z轴的数值
答案:2 悬赏:70 手机版
解决时间 2021-11-11 12:05
- 提问者网友:谁的错
- 2021-11-10 19:25
Android 怎么获得手机即时的重力感应的X,Y,Z轴的数值
最佳答案
- 五星知识达人网友:千杯敬自由
- 2021-11-10 20:50
重心感力是手机自带的软件功能,不可以下载吧,我没有用过。
全部回答
- 1楼网友:低血压的长颈鹿
- 2021-11-10 22:29
sensorMgr = (SensorManager) _main.getSystemService(SENSOR_SERVICE);
sensor = sensorMgr.getDefaultSensor(Sensor.TYPE_ACCELEROMETER);
SensorEventListener lsn = new SensorEventListener() {
public void onSensorChanged(SensorEvent e) {
x = e.values[SensorManager.DATA_X];
y = e.values[SensorManager.DATA_Y];
z = e.values[SensorManager.DATA_Z];
double g = x*x + y *y;
final int result1 = (int)(Math.acos(x/9.8)*180);
final int result2 = (int)(Math.acos(y/9.8)*180);
final int result3 = (int)(Math.acos(z/9.8)*180);
_main.runOnUiThread(new Runnable() {
@Override
public void run() {
radtxt.setText( String.valueOf(x)+" "+String.valueOf( y )+" "+String.valueOf( z ) );
}
});
}
public void onAccuracyChanged(Sensor s, int accuracy) {
}
};
sensorMgr.registerListener(lsn, sensor, SensorManager.SENSOR_DELAY_GAME);
sensor = sensorMgr.getDefaultSensor(Sensor.TYPE_ACCELEROMETER);
SensorEventListener lsn = new SensorEventListener() {
public void onSensorChanged(SensorEvent e) {
x = e.values[SensorManager.DATA_X];
y = e.values[SensorManager.DATA_Y];
z = e.values[SensorManager.DATA_Z];
double g = x*x + y *y;
final int result1 = (int)(Math.acos(x/9.8)*180);
final int result2 = (int)(Math.acos(y/9.8)*180);
final int result3 = (int)(Math.acos(z/9.8)*180);
_main.runOnUiThread(new Runnable() {
@Override
public void run() {
radtxt.setText( String.valueOf(x)+" "+String.valueOf( y )+" "+String.valueOf( z ) );
}
});
}
public void onAccuracyChanged(Sensor s, int accuracy) {
}
};
sensorMgr.registerListener(lsn, sensor, SensorManager.SENSOR_DELAY_GAME);
我要举报
如以上问答信息为低俗、色情、不良、暴力、侵权、涉及违法等信息,可以点下面链接进行举报!
大家都在看
推荐资讯