check Sensor Accelerometer - Android Hardware

Android examples for Hardware:Sensor

Description

check Sensor Accelerometer

Demo Code

/*//from   ww w . j  a va  2  s . c  om
 *  Copyright(c) 2013- AndroboGroup, All rights reserved.
 */
import java.util.List;
import android.content.Context;
import android.content.Intent;
import android.content.pm.PackageManager;
import android.content.pm.ResolveInfo;
import android.content.res.Configuration;
import android.hardware.Sensor;
import android.hardware.SensorManager;
import android.os.Build;

public class Main{
    static final String TAG = "CheckUtil";
    
    public static boolean checkSensorAccelerometer(Context context) {
        LogUtil.d(TAG, "[IN ] checkSensorAccelerometer()");

        boolean result;

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

        List<Sensor> sensors = sensorManager
                .getSensorList(Sensor.TYPE_ACCELEROMETER);

        if (0 < sensors.size()) {
            result = true;
        } else {
            result = false;
        }

        LogUtil.d(TAG, "result:" + result);
        LogUtil.d(TAG, "[OUT] checkSensorAccelerometer()");
        return result;
    }
}

Related Tutorials