is Sensor Available by sensor type - Android Hardware

Android examples for Hardware:Sensor

Description

is Sensor Available by sensor type

Demo Code


//package com.java2s;
import android.content.Context;
import android.hardware.SensorManager;

public class Main {
    public static boolean isSensorAvailable(Context ctx, int type_sensor) {
        boolean isSensorAvailable = false;
        SensorManager sensorManger = null;

        sensorManger = (SensorManager) ctx
                .getSystemService(ctx.SENSOR_SERVICE);

        if (sensorManger.getDefaultSensor(type_sensor) != null) {
            isSensorAvailable = true;/*from  w w  w . j a  va2s . c om*/
        }

        return isSensorAvailable;
    }
}

Related Tutorials