Android 휴대폰 내장 센서 수량 테스트 APIlevel 10
2699 단어 android(ec)
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;
}
}
}
}