android.hardware.SensorManager#getSensorList ( )源码实例Demo

下面列出了android.hardware.SensorManager#getSensorList ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

源代码1 项目: wear-os-samples   文件: MainWearActivity.java
public void onClickWearBodySensors(View view) {

        if (mWearBodySensorsPermissionApproved) {

            // To keep the sample simple, we are only displaying the number of sensors.
            SensorManager sensorManager = (SensorManager) getSystemService(SENSOR_SERVICE);
            List<Sensor> sensorList = sensorManager.getSensorList(Sensor.TYPE_ALL);
            int numberOfSensorsOnDevice = sensorList.size();

            logToUi(numberOfSensorsOnDevice + " sensors on device(s)!");

        } else {
            logToUi("Requested local permission.");
            // On 23+ (M+) devices, GPS permission not granted. Request permission.
            ActivityCompat.requestPermissions(
                    this,
                    new String[]{Manifest.permission.BODY_SENSORS},
                    PERMISSION_REQUEST_READ_BODY_SENSORS);
        }
    }
 
源代码2 项目: batteryhub   文件: MainActivity.java
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    setContentView(R.layout.activity_main);

    LogUtils.logI(TAG, "onCreate() called");

    loadComponents();

    Intent intentFromNotifier = getIntent();

    if (intentFromNotifier != null) {
        int tab = intentFromNotifier.getIntExtra("tab", -1);
        if (tab != -1) {
            mViewPager.setCurrentItem(tab);
        }
    }
    mSensorManager = (SensorManager) getBaseContext().getSystemService(Context.SENSOR_SERVICE);
    mSensorList = mSensorManager.getSensorList(Sensor.TYPE_ALL);
}
 
源代码3 项目: Women-Safety-App   文件: AccelerometerManager.java
/**
 * Returns true if at least one Accelerometer sensor is available
 */
public static boolean isSupported(Context context) {
    aContext = context;
    if (supported == null) {
        if (aContext != null) {
             
             
            sensorManager = (SensorManager) aContext.
                    getSystemService(Context.SENSOR_SERVICE);
             
            // Get all sensors in device
            List<Sensor> sensors = sensorManager.getSensorList(
                    Sensor.TYPE_ACCELEROMETER);
             
            supported = new Boolean(sensors.size() > 0);
             
             
             
        } else {
            supported = Boolean.FALSE;
        }
    }
    return supported;
}
 
@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    // we need to retrieve the system service on the parent activity
    mSensorManager = (SensorManager) getActivity().getSystemService(Context.SENSOR_SERVICE);

    // this is how to list all sensors
    deviceSensors = mSensorManager.getSensorList(Sensor.TYPE_ALL);

    // check for a specific type of sensor
    //if (mSensorManager.getDefaultSensor(Sensor.TYPE_MAGNETIC_FIELD) != null){
        // Success! There's a magnetometer.
    //}
    //else {
        // Failure! No magnetometer.
    //}

}
 
源代码5 项目: wearable   文件: MainActivity.java
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    setAmbientEnabled();

    mContainerView = (BoxInsetLayout) findViewById(R.id.container);
    mTextView = (TextView) findViewById(R.id.text);
    mData = (TextView) findViewById(R.id.data);

    sensorManager = (SensorManager) getSystemService(SENSOR_SERVICE);

    //write out to the log all the sensors the device has.
    sensors = sensorManager.getSensorList(Sensor.TYPE_ALL);
    if (sensors.size() < 1) {
        Toast.makeText(this, "No sensors returned from getSensorList", Toast.LENGTH_SHORT).show();
        Log.wtf(TAG,"No sensors returned from getSensorList");
    }
    Sensor[] sensorArray = sensors.toArray(new Sensor[sensors.size()]);
    for (int i = 0; i < sensorArray.length; i++) {
        Log.wtf(TAG,"Found sensor " + i + " " + sensorArray[i].toString());
    }
}
 
源代码6 项目: Sensor-Disabler   文件: SensorUtil.java
public static Sensor getSensorFromUniqueSensorKey(Context context, String key) {
    String[] data = key.split(Pattern.quote(SENSOR_SEPARATOR)); //Regex, man. Regex.
    if (data.length >= 4) {
        try {
            String name = data[0];
            String vendor = data[1];
            int version = Integer.parseInt(data[2]);
            int type = Integer.parseInt(data[3]);
            SensorManager manager = (SensorManager) context.getSystemService(Context.SENSOR_SERVICE);
            for (Sensor sensor : manager.getSensorList(type)) {
                if (sensor.getName().equals(name)
                        && sensor.getVendor().equals(vendor)
                        && sensor.getVersion() == version) {
                    return sensor;
                }
            }
        } catch (NumberFormatException e) {
            throw new IllegalArgumentException("Unable to get unique sensor from key.");
        }
    } else {
        Log.e("SensorUtil", "Unable to parse \"" + key + "\" as Sensor data.");
    }
    return null;
}
 
源代码7 项目: FtcSamples   文件: FtcTestAndroidSensors.java
@Override
    public void initRobot()
    {
        hardwareMap.logDevices();
        dashboard = HalDashboard.getInstance();
        FtcRobotControllerActivity activity = (FtcRobotControllerActivity)hardwareMap.appContext;
        dashboard.setTextView((TextView)activity.findViewById(R.id.textOpMode));
        //
        // Enumerates all Android sensors.
        //
        SensorManager sensorManager = (SensorManager)activity.getSystemService(Context.SENSOR_SERVICE);
        List<Sensor> sensorList = sensorManager.getSensorList(Sensor.TYPE_ALL);
        dashboard.displayPrintf(0, "Android Sensors:");
        int lineNum = 1;
        for (Sensor sensor: sensorList)
        {
            dashboard.displayPrintf(lineNum, "%02d->%s, %s, %d",
                                    sensor.getType(), sensor.getVendor(), sensor.getName(), sensor.getVersion());
            lineNum++;
            if (lineNum >= dashboard.getNumTextLines())
            {
                break;
            }
        }

        //
        // Create Android sensors.
        //
        accel = FtcAndroidSensor.createInstance("accel", Sensor.TYPE_ACCELEROMETER, 3);
        gravity = FtcAndroidSensor.createInstance("gravity", Sensor.TYPE_GRAVITY, 3);
        gyro = FtcAndroidSensor.createInstance("gyro", Sensor.TYPE_GYROSCOPE, 3);
        linearAccel = FtcAndroidSensor.createInstance("linearAccel", Sensor.TYPE_LINEAR_ACCELERATION, 3);
        rotation = FtcAndroidSensor.createInstance("rotation", Sensor.TYPE_ROTATION_VECTOR, 4);
        magnetic = FtcAndroidSensor.createInstance("magnetic", Sensor.TYPE_MAGNETIC_FIELD, 3);
//        orientation = FtcAndroidSensor.createInstance("orientation", Sensor.TYPE_ORIENTATION, 3);
        proximity = FtcAndroidSensor.createInstance("proximity", Sensor.TYPE_PROXIMITY, 1);
        light = FtcAndroidSensor.createInstance("light", Sensor.TYPE_LIGHT, 1);
    }
 
源代码8 项目: osmdroid   文件: DiagnosticsActivity.java
private void probeOrientation() {
    StringBuilder sb = new StringBuilder();
    SensorManager mSensorManager = (SensorManager) getSystemService(Context.SENSOR_SERVICE);
    List<Sensor> sensorList = mSensorManager.getSensorList(Sensor.TYPE_ORIENTATION);
    for (Sensor s : sensorList) {

        sb.append(s.getName() + ":" + s.toString() + "\n");
    }
    output.setText(sb.toString());
}
 
源代码9 项目: LLApp   文件: TemperatureActivity.java
@Override
protected void onInitView() {

    if(humidityView != null){
        humidityView.setPanelText("当前湿度");
        humidityView.setUnit(" %");
        humidityView.setTikeCount(40);
    }

    //获取传感器
    mSensorManager = (SensorManager) getSystemService(Context.SENSOR_SERVICE);
    //获取温度传感器
    mTemperaSensor = mSensorManager.getDefaultSensor(Sensor.TYPE_AMBIENT_TEMPERATURE);
    //获取湿度传感器
    mHumiditySensor = mSensorManager.getDefaultSensor(Sensor.TYPE_RELATIVE_HUMIDITY);

    List<Sensor> deviceSensors = mSensorManager.getSensorList(Sensor.TYPE_ALL);
    for (Sensor sensor : deviceSensors) {
        Log.i("sensor", "------------------");
        Log.i("sensor", sensor.getName());
        Log.i("sensor", sensor.getVendor());
        Log.i("sensor", Integer.toString(sensor.getType()));
        Log.i("sensor", "------------------");
    }

    if(mTemperaSensor == null){
        ToastUtil.showToast("您的设备暂不支持温度传感器功能");
    }

    if(mHumiditySensor == null){
        ToastUtil.showToast("您的设备暂不支持湿度传感器功能");
    }

    //给传感器注册一个时间监听器     监听传感器的数据的变化
    tempListener = new TempListener();
    humidityListener = new HumidityListener();

    mSensorManager.registerListener(tempListener,mTemperaSensor,SensorManager.SENSOR_DELAY_NORMAL);
    mSensorManager.registerListener(humidityListener,mHumiditySensor,SensorManager.SENSOR_DELAY_NORMAL);
}
 
源代码10 项目: unity-ads-android   文件: Device.java
public static List<Sensor> getSensorList () {
	if (ClientProperties.getApplicationContext() != null) {
		SensorManager sensorManager = (SensorManager)ClientProperties.getApplicationContext().getSystemService(Context.SENSOR_SERVICE);
		return sensorManager.getSensorList(Sensor.TYPE_ALL);
	}

	return null;
}
 
/**
 * Proximityのセンサーリストを取得する.
 * <p>
 * Proximityのセンサーに対応していない場合には、空の配列が返却される。
 * @return センサーリスト
 */
private List<Sensor> getSensorList() {
    SensorManager mgr = getSensorManager();
    if (mgr == null) {
        return new ArrayList<Sensor>();
    }
    return mgr.getSensorList(Sensor.TYPE_PROXIMITY);
}
 
源代码12 项目: AndroidDemoProjects   文件: SensorListFragment.java
@Override
public void onViewCreated(View view, Bundle savedInstanceState) {
	super.onViewCreated(view, savedInstanceState);

	mAdapter = new SensorListAdapter( getActivity() );
	setListAdapter(mAdapter);

	mSensorManager = (SensorManager) getActivity().getSystemService( Context.SENSOR_SERVICE );

	for( Sensor sensor : mSensorManager.getSensorList( Sensor.TYPE_ALL ) )
		mAdapter.add( sensor );
}
 
private void initSensors()
{
    // Add all sensors
    SensorManager mSensorManager = (SensorManager) this.context.getSystemService(Activity.SENSOR_SERVICE);
    List<Sensor> allSensors = mSensorManager.getSensorList(Sensor.TYPE_ALL);

    for(Sensor sensor : allSensors) {
        this.addSensorCollector(sensor.getType(), sensor);
    }

    for(int type : CollectorConstants.activatedCustomCollectors) {
        this.addCustomCollector(type, this.context);
    }
}
 
源代码14 项目: product-emm   文件: DeviceInfo.java
/**
 * Returns all the sensors available on the device as a List.
 * @return - List of all the sensors available on the device.
 */
public List<Sensor> getAllSensors() {
	SensorManager sensorManager =
                             (SensorManager) context.getSystemService(Context.SENSOR_SERVICE);
	
	return sensorManager.getSensorList(Sensor.TYPE_ALL);
}
 
源代码15 项目: CameraV   文件: AccelerometerSucker.java
@SuppressWarnings("unchecked")
public AccelerometerSucker(Context context) {
	super(context);
	setSucker(this);
	
       df.setMaximumFractionDigits(1);
       df.setPositivePrefix("+");
	
	sm = (SensorManager)context.getApplicationContext().getSystemService(Context.SENSOR_SERVICE);
	availableSensors = sm.getSensorList(Sensor.TYPE_ALL);
	
	for(Sensor s : availableSensors) {
		switch(s.getType()) {
		case Sensor.TYPE_ACCELEROMETER:
			hasAccelerometer = true;
			sm.registerListener(this, s, SensorManager.SENSOR_DELAY_GAME);
			break;
		case Sensor.TYPE_MAGNETIC_FIELD:
			sm.registerListener(this, s, SensorManager.SENSOR_DELAY_GAME);
			hasOrientation = true;
			break;
			
		
		}
			
	}
	
	setTask(new TimerTask() {
		
		@Override
		public void run() {
			try {
				if(hasAccelerometer)
					readAccelerometer();
				if(hasOrientation)
					readOrientation();
			} catch(JSONException e){}
		}
	});
	
	getTimer().schedule(getTask(), 0, Accelerometer.LOG_RATE);
}
 
源代码16 项目: Compass   文件: SensorUtil.java
public static boolean hasGravitySensor(Context context) {
    SensorManager sensorManager = (SensorManager) context.getSystemService(Context.SENSOR_SERVICE);
    List<Sensor> listSensors = sensorManager.getSensorList(Sensor.TYPE_GRAVITY);
    return !listSensors.isEmpty();
}
 
源代码17 项目: Compass   文件: SensorUtil.java
public static boolean hasMagnetometer(Context context) {
    SensorManager sensorManager = (SensorManager) context.getSystemService(Context.SENSOR_SERVICE);

    List<Sensor> listSensors = sensorManager.getSensorList(Sensor.TYPE_MAGNETIC_FIELD);
    return !listSensors.isEmpty();
}
 
源代码18 项目: Compass   文件: SensorUtil.java
public static boolean hasAccelerometer(Context context) {
    SensorManager sensorManager = (SensorManager) context.getSystemService(Context.SENSOR_SERVICE);

    List<Sensor> listSensors = sensorManager.getSensorList(Sensor.TYPE_ACCELEROMETER);
    return !listSensors.isEmpty();
}
 
源代码19 项目: Compass   文件: SensorUtil.java
public static boolean hasRotationVector(Context context) {
    SensorManager sensorManager = (SensorManager) context.getSystemService(Context.SENSOR_SERVICE);

    List<Sensor> listSensors = sensorManager.getSensorList(Sensor.TYPE_ROTATION_VECTOR);
    return !listSensors.isEmpty();
}
 
源代码20 项目: CameraV   文件: EnvironmentalSucker.java
@SuppressWarnings({ "unchecked", "deprecation" })
public EnvironmentalSucker(Context context) {
	super(context);
	setSucker(this);
	
	sm = (SensorManager)context.getApplicationContext().getSystemService(Context.SENSOR_SERVICE);
	availableSensors = sm.getSensorList(Sensor.TYPE_ALL);
	
	for(Sensor s : availableSensors) {
		switch(s.getType()) {
		case Sensor.TYPE_AMBIENT_TEMPERATURE:
			sm.registerListener(this, s, SensorManager.SENSOR_DELAY_NORMAL);
			break;
		case Sensor.TYPE_RELATIVE_HUMIDITY:
			sm.registerListener(this, s, SensorManager.SENSOR_DELAY_NORMAL);
			break;
		case Sensor.TYPE_PRESSURE:
			sm.registerListener(this, s, SensorManager.SENSOR_DELAY_NORMAL);
			break;
		case Sensor.TYPE_LIGHT:
			sm.registerListener(this, s, SensorManager.SENSOR_DELAY_NORMAL);
			break;				
		case Sensor.TYPE_TEMPERATURE:
			sm.registerListener(this, s, SensorManager.SENSOR_DELAY_NORMAL);
			break;
		}
			
	}
	
	setTask(new TimerTask() {
		
		@Override
		public void run() {
				if(currentAmbientTemp != null)
					sendToBuffer(currentAmbientTemp);
				if(currentDeviceTemp != null)
					sendToBuffer(currentDeviceTemp);
				if(currentHumidity != null)
					sendToBuffer(currentHumidity);
				if(currentPressure != null)
					sendToBuffer(currentPressure);
				if(currentLight != null)
					sendToBuffer(currentLight);
		}
	});
	
	getTimer().schedule(getTask(), 0, Environment.LOG_RATE);
}