Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

//package com.java2s;

import android.hardware.Sensor;

import android.hardware.SensorManager;
import java.util.ArrayList;
import java.util.List;

public class Main {
    private static SensorManager sensorManager;

    public static List<Sensor> getCompatibleSensors() {
        List<Sensor> compatible = new ArrayList<>();
        List<Sensor> all = getAllSensors();
        for (Sensor sensor : all) {
            if (isSensorCompatible(sensor)) {
                compatible.add(sensor);
            }
        }
        return compatible;
    }

    public static List<Sensor> getAllSensors() {
        return sensorManager.getSensorList(Sensor.TYPE_ALL);
    }

    public static boolean isSensorCompatible(Sensor sensor) {
        return sensor.getType() == Sensor.TYPE_STEP_COUNTER || sensor.getType() == Sensor.TYPE_STEP_DETECTOR
                || sensor.getType() == Sensor.TYPE_LIGHT || sensor.getType() == Sensor.TYPE_PRESSURE
                || sensor.getType() == Sensor.TYPE_RELATIVE_HUMIDITY
                || sensor.getType() == Sensor.TYPE_SIGNIFICANT_MOTION || sensor.getType() == Sensor.TYPE_GRAVITY;
    }
}