Example usage for android.hardware SensorManager getSensorList

List of usage examples for android.hardware SensorManager getSensorList

Introduction

In this page you can find the example usage for android.hardware SensorManager getSensorList.

Prototype

public List<Sensor> getSensorList(int type) 

Source Link

Document

Use this method to get the list of available sensors of a certain type.

Usage

From source file:Main.java

public static boolean checkSensor(int sensor, Context context) {
    SensorManager sensorManger = (SensorManager) context.getApplicationContext()
            .getSystemService(Context.SENSOR_SERVICE);
    List<Sensor> lista = sensorManger.getSensorList(sensor);
    return lista.size() > 0;

}

From source file:altermarkive.uploader.Report.java

@SuppressWarnings("unused")
public static String probe(Context context) throws JSONException {
    SensorManager manager = (SensorManager) context.getSystemService(Context.SENSOR_SERVICE);
    List<Sensor> list = manager.getSensorList(Sensor.TYPE_ALL);
    int[] types = new int[list.size()];
    String[] vendors = new String[list.size()];
    String[] names = new String[list.size()];
    float[] resolutions = new float[list.size()];
    int[] delays = new int[list.size()];
    float[] ranges = new float[list.size()];
    float[] powers = new float[list.size()];
    int i = 0;//w w  w  . ja  va  2s. co m
    for (Sensor sensor : list) {
        types[i] = sensor.getType();
        vendors[i] = sensor.getVendor();
        names[i] = sensor.getName();
        resolutions[i] = sensor.getResolution();
        delays[i] = sensor.getMinDelay();
        ranges[i] = sensor.getMaximumRange();
        powers[i] = sensor.getPower();
        i++;
    }
    return report(context, types, vendors, names, resolutions, delays, ranges, powers);
}

From source file:com.acrr.acdisplay.services.activemode.ActiveModeService.java

public static boolean isSupported(@NonNull Context context) {
    SensorManager sensorManager = (SensorManager) context.getSystemService(Context.SENSOR_SERVICE);
    return sensorManager.getSensorList(Sensor.TYPE_PROXIMITY).size() > 0;
}

From source file:de.da_sense.moses.client.abstraction.HardwareAbstraction.java

/**
 * Get all available sensors from the operating system.
 * //  ww  w .j av a 2s.c  o m
 * @return All available sensors on this device
 */
public static List<Sensor> getSensors() {
    if (MosesService.getInstance() != null) {
        List<Sensor> sensors = new ArrayList<Sensor>();
        SensorManager s = (SensorManager) MosesService.getInstance().getSystemService(Context.SENSOR_SERVICE);
        for (Sensor sen : s.getSensorList(Sensor.TYPE_ALL))
            sensors.add(sen);
        return sensors;
    } else {
        return null;
    }
}

From source file:ch.bfh.sensordataprocessor.sensor.SensorSelectorFragment.java

/**
 * connect with a display fragment to call later when user clicks a sensor
 * name, also setup the ListAdapter to show all the Sensors
 */// w w w .j a  va 2s . c o m
public void setSensorDisplay(SensorDisplayFragment sensorDisplay) {
    this.sensorDisplay = sensorDisplay;

    SensorManager sensorManager = (SensorManager) getActivity().getSystemService(Activity.SENSOR_SERVICE);
    List<Sensor> sensors = sensorManager.getSensorList(Sensor.TYPE_ALL);
    this.setListAdapter(new SensorListAdapter(getActivity().getApplicationContext(),
            android.R.layout.simple_list_item_1, sensors));
}

From source file:org.jitsi.android.gui.fragment.ProximitySensorFragment.java

/**
 * {@inheritDoc}// w  w w  .  j  av a  2  s .com
 */
@Override
public void onResume() {
    super.onResume();

    // Skips if the sensor has been already attached
    if (proximitySensor != null)
        return;

    SensorManager manager = JitsiApplication.getSensorManager();

    List<Sensor> sensors = manager.getSensorList(Sensor.TYPE_ALL);
    logger.trace("Device has " + sensors.size() + " sensors");
    for (Sensor s : sensors) {
        logger.trace("Sensor " + s.getName() + " type: " + s.getType());
    }

    this.proximitySensor = manager.getDefaultSensor(Sensor.TYPE_PROXIMITY);
    if (proximitySensor == null) {
        return;
    }

    logger.info("Using proximity sensor: " + proximitySensor.getName());
    sensorDisabled = false;
    manager.registerListener(this, proximitySensor, SensorManager.SENSOR_DELAY_UI);
}

From source file:de.tubs.ibr.dtn.dtalkie.TalkieActivity.java

@Override
public void onResume() {
    super.onResume();

    SensorManager sm = (SensorManager) getSystemService(Context.SENSOR_SERVICE);
    List<Sensor> sensors = sm.getSensorList(Sensor.TYPE_PROXIMITY);
    if (sensors.size() > 0) {
        Sensor sensor = sensors.get(0);//www  .j  av a 2s.c  om
        sm.registerListener(mSensorListener, sensor, SensorManager.SENSOR_DELAY_NORMAL);
    }

    // set output to speaker
    setAudioOutput();
}

From source file:com.example.android.wearable.runtimepermissions.IncomingRequestWearService.java

private void respondWithSensorInformation() {
    Log.d(TAG, "respondWithSensorInformation()");

    boolean sensorPermissionApproved = ActivityCompat.checkSelfPermission(this,
            Manifest.permission.BODY_SENSORS) == PackageManager.PERMISSION_GRANTED;

    if (!sensorPermissionApproved) {
        DataMap dataMap = new DataMap();
        dataMap.putInt(Constants.KEY_COMM_TYPE, Constants.COMM_TYPE_RESPONSE_PERMISSION_REQUIRED);
        sendMessage(dataMap);//w  w  w  .j  a va 2 s.c om
    } else {
        /* To keep the sample simple, we are only displaying the number of sensors. You could do
         * something much more complicated.
         */
        SensorManager sensorManager = (SensorManager) getSystemService(SENSOR_SERVICE);
        List<Sensor> sensorList = sensorManager.getSensorList(Sensor.TYPE_ALL);
        int numberOfSensorsOnDevice = sensorList.size();

        String sensorSummary = numberOfSensorsOnDevice + " sensors on wear device(s)!";
        DataMap dataMap = new DataMap();
        dataMap.putInt(Constants.KEY_COMM_TYPE, Constants.COMM_TYPE_RESPONSE_DATA);
        dataMap.putString(Constants.KEY_PAYLOAD, sensorSummary);
        sendMessage(dataMap);
    }
}

From source file:com.fallahpoor.infocenter.fragments.SensorsFragment.java

@TargetApi(Build.VERSION_CODES.KITKAT)
public ArrayList<String> getSubItemsArrayList() {

    HashMap<Integer, String> sensorsHashMap = new HashMap<>();
    ArrayList<String> subItems = new ArrayList<>();
    Iterator<Integer> iterator;
    String supported = getString(R.string.supported);
    String unsupported = getString(R.string.unsupported);
    ArrayList<Integer> sensorTypes = new ArrayList<>(Arrays.asList(new Integer[] { Sensor.TYPE_ACCELEROMETER,
            Sensor.TYPE_AMBIENT_TEMPERATURE, Sensor.TYPE_GRAVITY, Sensor.TYPE_GYROSCOPE, Sensor.TYPE_LIGHT,
            Sensor.TYPE_LINEAR_ACCELERATION, Sensor.TYPE_MAGNETIC_FIELD, Sensor.TYPE_PRESSURE,
            Sensor.TYPE_PROXIMITY, Sensor.TYPE_RELATIVE_HUMIDITY, Sensor.TYPE_ROTATION_VECTOR }));

    if (mIsApiAtLeast18) {
        sensorTypes.add(Sensor.TYPE_GAME_ROTATION_VECTOR);
        sensorTypes.add(Sensor.TYPE_SIGNIFICANT_MOTION);
    }/*ww w . ja  va  2s  .  c o m*/

    if (mIsApiAtLeast19) {
        sensorTypes.add(Sensor.TYPE_GEOMAGNETIC_ROTATION_VECTOR);
        sensorTypes.add(Sensor.TYPE_STEP_COUNTER);
        sensorTypes.add(Sensor.TYPE_STEP_DETECTOR);
    }

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

    // Get the list of all available sensors of the device
    List<Sensor> sensors = sensorManager.getSensorList(Sensor.TYPE_ALL);

    iterator = sensorTypes.iterator();

    // Assume all sensor types are unsupported
    while (iterator.hasNext()) {
        sensorsHashMap.put(iterator.next(), unsupported);
    }

    /*
     * For each sensor type that is in sensors change its status from
     * "unsupported" to "supported".
     */
    for (Sensor sensor : sensors) {
        sensorsHashMap.put(sensor.getType(), supported);
    }

    iterator = sensorTypes.iterator();

    while (iterator.hasNext()) {
        subItems.add(sensorsHashMap.get(iterator.next()));
    }

    return subItems;

}

From source file:com.wso2.mobile.mdm.api.DeviceInfo.java

/**
*Returns all the sensors available on the device as a List
*/// w ww . j  a  va  2  s . c om
public void getAllSensors() {
    SensorManager sm = (SensorManager) context.getSystemService(Context.SENSOR_SERVICE);
    List<Sensor> list = sm.getSensorList(Sensor.TYPE_ALL);

    if (CommonUtilities.DEBUG_MODE_ENABLED) {
        for (Sensor s : list) {
            Log.d("SENSORS", s.getName());
        }
    }
}