0

I'm developing an app for a personal project , and I will need to process the data later on on Matlab (for power requirements). Hence, my goal would be to "store" a value of the light sensor every two second, in an array ? Right now, I am able to correctly show the value of the sensor in real time, displayed on screen based on the default frequency of the smartphone ! I'm quite novice in Android, and I'm learning everyday haha ! I'm just stuck there... The final goal would be to send the data to a database and create a graph of it later on .. showing the light intensity of a place in term of time .. What would be the best storage please? Best regards,

private final SensorEventListener LightSensorListener = new SensorEventListener() {
    @Override
    public void onSensorChanged(SensorEvent event) {
        if(event.sensor.getType() == Sensor.TYPE_LIGHT){
            textLight_reading.setText("LIGHT : " + event.values[0]);
        }
    }
    @Override
    public void onAccuracyChanged(Sensor sensor, int accuracy) {

    }
};

And here is the other part of the code :

textLight_available = (TextView) findViewById(R.id.LIGHT_available);
    textLight_reading = (TextView) findViewById(R.id.LIGHT_reading);


    SensorManager mySensorManager = (SensorManager) getSystemService(SENSOR_SERVICE);
    Sensor LightSensor = mySensorManager.getDefaultSensor(Sensor.TYPE_LIGHT);

    super.onResume();
    if (LightSensor != null) {
        textLight_available.setText("LIGHT SENSOR ON");
        mySensorManager.registerListener(LightSensorListener, LightSensor,
                SensorManager.SENSOR_DELAY_NORMAL);
    } else {
        textLight_available.setText("LIGHT SENSOR OFF");
    }
Sacha G.
  • 9
  • 1

1 Answers1

0

As per your description you need to store data every two seconds I guess that will be huge amount of data depending on time

First you may create an array of your data objects and keep on adding items to that every 2 seconds and keep on pushing that array to sqlite database every minute for persistent storage

if you go with writing sqlite db every two seconds it may lead to issues

Happy coding :)

Sourabh Saldi
  • 3,567
  • 6
  • 34
  • 57