??????????

???????????????????????????????????????С?????ū??С?????????????????????????????????????????????????????????????Я???????????2002?????????????????Dell??PDA??2007??????????????N73??????2010????????????Milestone???????????????????????????????????????Щ???????????????????????????ν??????????????????????????????????????

????2008???????????????С?????Macbook??????????????С????????????????????????????????????????????????????????С?????????????????????????????????????????????д???????

??????????iPhone?????????????????????????????????????????????????iPhone?????????????????????????????????Android?????????????????????????Android????????????????????????Windows CE???????????????????????Milestone??????N73??????????????????

??????Android1.5???????????????????????????????????????????????????accelerometer???????????gyroscope???????????????????light????????????????magnetic field??????????????orientation???????????????pressure??????????????proximity??????????????temperature????

??????????Щ??????????????????????????????ó?????????????????????????????????????????????????????????????????????????????β??????????С??á?

????????????????????????????????????????????????????????????????????????Android??????????б??????????

???????????????????????嵥

???????????????????????

????1???????????? Lesson37_HelloSensor ????Activity????? mainActivity.java??

????2??UI???????main.xml?????????£?
????XML/HTML????

<?xml version="1.0" encoding="utf-8"?>  
<linearlayout android:layout_height="fill_parent" android:layout_width="fill_parent" android:orientation="vertical" xmlns:android="http://schemas.android.com/apk/res/android">  
<textview android:layout_height="wrap_content" android:layout_width="fill_parent" android:text="" android:id="@+id/TextView01">  
</textview></linearlayout>  
 
????3??mainActivity.java?????????£?
????
 
package basic.android.lesson37;   
  
import java.util.List;   
  
import android.app.Activity;   
import android.content.Context;   
import android.hardware.Sensor;   
import android.hardware.SensorManager;   
import android.os.Bundle;   
import android.widget.TextView;   
  
public class MainActivity extends Activity {   
  
        /** Called when the activity is first created. */  
        @Override  
        public void onCreate(Bundle savedInstanceState) {   
                super.onCreate(savedInstanceState);   
                setContentView(R.layout.main);   
  
                //???????????UI?齨   
                final TextView tx1 = (TextView) findViewById(R.id.TextView01);   
  
                //?????????л?????????????   
                SensorManager sm = (SensorManager) getSystemService(Context.SENSOR_SERVICE);   
  
                //??????????????л?????????????б?   
                List<sensor> allSensors = sm.getSensorList(Sensor.TYPE_ALL);   
  
                //????ж??????????   
                tx1.setText("???????????" + allSensors.size() + "??????????????????? ");   
  
                //????????????????????   
                for (Sensor s : allSensors) {   
  
                        String tempString = " " + "  ?豸?????" + s.getName() + " " + "  ?豸?汾??" + s.getVersion() + " " + "  ??????"  
                                        + s.getVendor() + " ";   
  
                        switch (s.getType()) {   
                        case Sensor.TYPE_ACCELEROMETER:   
                                tx1.setText(tx1.getText().toString() + s.getType() + " ??????????accelerometer" + tempString);   
                                break;   
                        case Sensor.TYPE_GYROSCOPE:   
                                tx1.setText(tx1.getText().toString() + s.getType() + " ???????????gyroscope" + tempString);   
                                break;   
                        case Sensor.TYPE_LIGHT:   
                                tx1.setText(tx1.getText().toString() + s.getType() + " ?????????????light" + tempString);   
                                break;   
                        case Sensor.TYPE_MAGNETIC_FIELD:   
                                tx1.setText(tx1.getText().toString() + s.getType() + " ??????????magnetic field" + tempString);   
                                break;   
                        case Sensor.TYPE_ORIENTATION:   
                                tx1.setText(tx1.getText().toString() + s.getType() + " ????????orientation" + tempString);   
                                break;   
                        case Sensor.TYPE_PRESSURE:   
                                tx1.setText(tx1.getText().toString() + s.getType() + " ?????????pressure" + tempString);   
                                break;   
                        case Sensor.TYPE_PROXIMITY:   
                                tx1.setText(tx1.getText().toString() + s.getType() + " ????????proximity" + tempString);   
                                break;   
                        case Sensor.TYPE_TEMPERATURE:   
                                tx1.setText(tx1.getText().toString() + s.getType() + " ????????temperature" + tempString);   
                                break;   
                        default:   
                                tx1.setText(tx1.getText().toString() + s.getType() + " δ???????" + tempString);   
                                break;   
                        }   
                }   
  
        }   
}</sensor>  
????4?????????Milestone?????????г????????????£?

????5????????????????????Щ?????

????1??Android???е?????????鴫?????????? SensorManager ??????????????????????????????

String service_name = Context.SENSOR_SERVICE;

SensorManager sensorManager = (SensorManager)getSystemService(service_name);

????2??????Android???????????8????????????

????3????????????????л??????????????Щ??????????????????????

???????????????????????????????

Sensor defaultGyroscope = sensorManager.getDefaultSensor(Sensor.TYPE_GYROSCOPE);

????????????????????????б?

List<Sensor> pressureSensors = sensorManager.getSensorList(Sensor.TYPE_PRESSURE);

?????????????????д????????б?????????????????????

List<Sensor> allSensors = sensorManager.getSensorList(Sensor.TYPE_ALL);

????4???????????????????????Щ?????????????????????±??