简体   繁体   中英

Collect synchronize data from different sensor in Android

I doing an app that collect data from the different sensor that are in a smart-phone. My doubts are : how I can collect different data? My goal is create an Matrix of array. There are the data capture from the signal in every row in the same time. If I use "timestamp " in the code above, it could be ok? I am not sure, because the definition of timestamp is "the time on which the event occur", but the problem is that the event can occur only in one sensor. Sincerely I am a bit confused about it.

mSensorManager = (SensorManager) this
                .getSystemService(Context.SENSOR_SERVICE);
mSensorListener = new SensorEventListener() {
    @Override
    public void onAccuracyChanged(Sensor arg0, int arg1) {
    }`enter code here`

    @Override
    public void onSensorChanged(SensorEvent event) {
        Sensor sensor = event.sensor;
        if (sensor.getType() == Sensor.TYPE_ACCELEROMETER) {
            //TODO: get values
        }else if (sensor.getType() == Sensor.TYPE_ORIENTATION) {
            //TODO: get values
        }
    }
}

I think you could benefit from a TreeMap . In your case i see it as a TreeMap<Long, Map<Integer, Float>>

The TreeMap will map timestamps (which you can get with System.currentTimeMillis() to whatever measurements were taken at those moments. The fact that it's a TreeMap will sort the entries according to the keys (so they will be in ascending order relative to the timestamps)

The measurements are a Map<Integer, Float> which maps sensor types that took measurements to the values of the measurements (which i will assume to be Float).

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM