Android 휴대폰 내장 센서 수량 테스트 APIlevel 10

2699 단어 android(ec)
자신의 휴대전화는 2.3.3이다. 그래서 어떤 센서가 있는지 테스트하고 다른 사람의 코드를 참고하여 그 다음에 몇 개의 센서를 추가했다.
public class SensorListActivity extends Activity {
	@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 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; case Sensor.TYPE_GRAVITY: tx1.setText(tx1.getText().toString() + s.getType() + " gravity" + tempString); break; case Sensor.TYPE_LINEAR_ACCELERATION: tx1.setText(tx1.getText().toString() + s.getType() + " " + tempString); break; case Sensor.TYPE_ROTATION_VECTOR: tx1.setText(tx1.getText().toString() + s.getType() + " " + tempString); break; default: tx1.setText(tx1.getText().toString() + s.getType() + " " + tempString); break; } } } }

좋은 웹페이지 즐겨찾기