나는 갤럭시 노트와 동일한 문제가 있었고 태블릿이나 전화를 결정하는 방법에 대한 조언을 받았습니다. 다른 게시글에 있지만 링크를 기억할 수 없습니다. 코드는 다음과 같습니다
public void onSensorChanged(SensorEvent event) {
// Note: Not all sensor events will supply both accelerometer and
// mag-field
int s = event.sensor.getType();
switch (s) {
case Sensor.TYPE_ACCELEROMETER:
aValues = lowPass(event.values.clone(), aValues);
break;
case Sensor.TYPE_MAGNETIC_FIELD:
mValues = lowPass(event.values.clone(), mValues);
break;
}
float[] R = new float[16]; // Rotation Matrix result goes here
float[] I = new float[9]; // Inclination Matrix result goes here
float[] oValues = new float[3]; // used for new orientation
boolean success = SensorManager.getRotationMatrix(R, I, aValues,
mValues);
// if both aValues and mValues are not null success will be true
// Also returns the Inclination Matrix
if (success) {
// Now get the device's orientation from the Rotation and
// Inclination Matrices
SensorManager.getOrientation(R, oValues);
// Change Radians to Degrees
oValues[0] = (360 + (float) Math.toDegrees(oValues[0])) % 360;
oValues[1] = (float) Math.toDegrees(oValues[1]);
oValues[2] = (float) Math.toDegrees(oValues[2]);
azimuth = oValues[0];//
y_az = oValues[1];// orientationValues[1];
z_az = oValues[2];// =
// test portrait or landscape (different on Tablets)
int test = getResources().getConfiguration().orientation;
// if necessary, azimuth = azimuth+270f or + 90f %360
heading.setText("X:" + Math.round(azimuth) + " Y:"
+ Math.round(y_az) + " Z: " + Math.round(z_az)
+ " degrees");
}
}
나는 대부분의 사용자가 방향을 것이기 때문에 가로 모드에서 태블릿 숙박셔서 결국 :이 작업을 수행 한 후, 나는 sensorlistener 코드에서 방위각 설정을 번역
DisplayMetrics metrics = this.getResources().getDisplayMetrics();
int screenWidth = metrics.widthPixels;
int screenHeight = metrics.heightPixels;
double inches = Math.sqrt((metrics.widthPixels * metrics.widthPixels)
+ (metrics.heightPixels * metrics.heightPixels))
/metrics.densityDpi;
// tablets typically larger than 6"" diagonally
// this is attempt to orient both player and magnetic sensors
if (inches > 6) {
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);
} else
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
그런 식으로 북한은 풍경의 꼭대기에 있습니다. 내 신인 코드가 (다른 사람들의 도움을 충분히 받으면서) 당신을 도울 수 있기를 바랍니다.
출처
2013-07-25 21:09:49
bob