Android获得当前设备支持的所有传感器

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());
        }
    }
}

上一篇:好程序员前端分享HTML5 智能表单


下一篇:不再容忍打不还手 英国将报复国家支持的黑客攻击