Example usage for android.content Context SENSOR_SERVICE

List of usage examples for android.content Context SENSOR_SERVICE

Introduction

In this page you can find the example usage for android.content Context SENSOR_SERVICE.

Prototype

String SENSOR_SERVICE

To view the source code for android.content Context SENSOR_SERVICE.

Click Source Link

Document

Use with #getSystemService(String) to retrieve a android.hardware.SensorManager for accessing sensors.

Usage

From source file:Main.java

public static boolean isSupportAccelerometerSensor(Context context) {
    SensorManager sensorManager = (SensorManager) context.getSystemService(Context.SENSOR_SERVICE);
    return sensorManager.getDefaultSensor(Sensor.TYPE_ACCELEROMETER) != null;
}

From source file:Main.java

/**
 * To determine whether it contains a gyroscope
 * /*w ww .  ja  va  2 s . com*/
 * @return
 */
public static boolean isHaveGravity(Context context) {
    SensorManager manager = (SensorManager) context.getSystemService(Context.SENSOR_SERVICE);
    if (manager == null) {
        return false;
    }
    return true;
}

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:Main.java

public static boolean hasDefaultSensor(Activity activity, int type) {
    boolean oneShot = false;
    boolean result = false;

    if (sensorManager == null) {
        oneShot = true;//from   w w  w  .  j a  v a  2 s  .  com
        sensorManager = (SensorManager) activity.getSystemService(Context.SENSOR_SERVICE);
    }
    if (sensorManager != null) {
        result = (sensorManager.getDefaultSensor(type) != null);
        if (oneShot) {
            sensorManager = null;
        }
    }

    return result;
}

From source file:Main.java

/**
 * Returns true if at least one Accelerometer sensor is available
 *///from   ww w. j av a2  s .  c  o  m
public static boolean isSupported() {
    //Log.v(AccelerometerUtils.class.getClass().getCanonicalName(), "isSupported Accelerometer "+supported+" "+oContext);
    if (supported == null) {
        if (oContext != null) {
            sensorManager = (SensorManager) oContext.getSystemService(Context.SENSOR_SERVICE);
            List<Sensor> sensors = sensorManager.getSensorList(Sensor.TYPE_ACCELEROMETER);
            supported = new Boolean(sensors.size() > 0);
        } else {
            supported = Boolean.FALSE;
        }
    }
    return supported;
}

From source file:org.mozilla.mozstumbler.service.stumblerthread.motiondetection.SignificantMotionSensor.java

public static SignificantMotionSensor getSensor(Context appCtx) {

    mSensorManager = (SensorManager) appCtx.getSystemService(Context.SENSOR_SERVICE);
    Sensor significantSensor;//from  w  w w . j  ava2s  . c  o m
    if (mSensorManager == null) {
        AppGlobals.guiLogInfo("No sensor manager.");
        return null;
    }

    if (Build.VERSION.SDK_INT >= 18) {
        significantSensor = mSensorManager.getDefaultSensor(Sensor.TYPE_SIGNIFICANT_MOTION);
        if (significantSensor != null) {
            AppGlobals.guiLogInfo("Device has significant motion sensor.");
            return new SignificantMotionSensor(appCtx, significantSensor);
        }
    }
    return null;
}

From source file:MainActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    ListView listView = (ListView) findViewById(R.id.list);
    List sensorList = new ArrayList<String>();

    List<Sensor> sensors = ((SensorManager) getSystemService(Context.SENSOR_SERVICE))
            .getSensorList(Sensor.TYPE_ALL);
    for (Sensor sensor : sensors) {
        sensorList.add(sensor.getName());
    }//from w ww.j  a  va2s  .c o  m
    ListAdapter sensorAdapter = new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1, sensorList);
    listView.setAdapter(sensorAdapter);

}

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;//from  w ww.ja  va2 s .com
    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:MainActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    mTextView = (TextView) findViewById(R.id.textView);
    mSensorManager = (SensorManager) getSystemService(Context.SENSOR_SERVICE);
    mSensor = mSensorManager.getDefaultSensor(Sensor.TYPE_LIGHT);
}

From source file:MyActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    setContentView(R.layout.main);//  www  .  j av  a2  s  .co  m
    sensorManager = (SensorManager) getSystemService(Context.SENSOR_SERVICE);
    magFieldSensor = sensorManager.getDefaultSensor(TYPE_MAGNETIC_FIELD);
    accelerometer = sensorManager.getDefaultSensor(TYPE_ACCELEROMETER);

    sensorListener = new MySensorEventListener();

    locationListener = new MyLocationListener();
    locationManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE);

    orientationView = (TextView) findViewById(R.id.orientationView);
    locationView = (TextView) findViewById(R.id.locationView);
}