package zhangphil.sensor;
import android.content.Context;
import android.hardware.Sensor;
import android.hardware.SensorManager;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.util.Log;
import java.util.List;
public class MainActivity extends AppCompatActivity {
private SensorManager mSensorManager;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
startSensor();
}
private void startSensor() {
mSensorManager = (SensorManager) this.getSystemService(Context.SENSOR_SERVICE);
if (mSensorManager == null) {
throw new UnsupportedOperationException();
}
List<Sensor> sensorsList = mSensorManager.getSensorList(Sensor.TYPE_ALL);
for (Sensor sensor : sensorsList) {
Log.d("支持的传感器", sensor.getName().toString());
}
}
}