WEB开发网
开发学院手机开发Android 开发 深入探讨 Android 传感器 阅读

深入探讨 Android 传感器

 2010-07-21 01:10:00 来源:WEB开发网   
核心提示:== SensorManager.SENSOR_ORIENTATION) { xViewO.setText("Orientation X: " + values[0]); yViewO.setText("Orientation Y: " + values[1]); zViewO.
== SensorManager.SENSOR_ORIENTATION) { xViewO.setText("Orientation X: " + values[0]); yViewO.setText("Orientation Y: " + values[1]); zViewO.setText("Orientation Z: " + values[2]); } if (sensor == SensorManager.SENSOR_ACCELEROMETER) { xViewA.setText("Accel X: " + values[0]); yViewA.setText("Accel Y: " + values[1]); zViewA.setText("Accel Z: " + values[2]); } } } public void onAccuracyChanged(int sensor, int accuracy) { Log.d(tag,"onAccuracyChanged: " + sensor + ", accuracy: " + accuracy); } @Override protected void onResume() { super.onResume(); // register this class as a listener for the orientation and accelerometer sensors sm.registerListener(this, SensorManager.SENSOR_ORIENTATION |SensorManager.SENSOR_ACCELEROMETER, SensorManager.SENSOR_DELAY_NORMAL); } @Override protected void onStop() { // unregister listener sm.unregisterListener(this); super.onStop(); } } package com.msi.ibm.eyes;

import android.app.Activity;

import android.os.Bundle;

import android.util.Log;

import android.widget.TextView;

import android.hardware.SensorManager;

import android.hardware.SensorListener;

public class IBMEyes extends Activity implements SensorListener {

final String tag = "IBMEyes";

SensorManager sm = null;

TextView xViewA = null;

TextView yViewA = null;

TextView zViewA = null;

TextView xViewO = null;

TextView yViewO = null;

TextView zViewO = null;

/** Called when the activity is first created. */

@Override

public void onCreate(Bundle savedInstanceState) {

super.onCreate(savedInstanceState);

// get reference to SensorManager

sm = (SensorManager) getSystemService(SENSOR_SERVICE);

setContentView(R.layout.main);

xViewA = (TextView) findViewById(R.id.xbox);

yViewA = (TextView) findViewById(R.id.ybox);

上一页  1 2 3 4 5 6 7 8 9  下一页

Tags:深入 探讨 Android

编辑录入:coldstar [复制链接] [打 印]
赞助商链接