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()); } } }
原创文章,作者:ItWorker,如若转载,请注明出处:https://blog.ytso.com/3122.html