Nurul Haque Saad
Nurul Haque Saad

Reputation: 1

How to pass the multiple sensor values to the notification bar in android when the app is in the background

I am a newbie in android sensors and notifications. I am working with sensor data(light, proximity, accelerometer, and gyroscope sensor). My goal is to make an app that will be displaying four sensor values in four different card views. I have done that properly. But I am getting stuck with how to run that app in the background after closing the app from the task manager and how the four live sensor values display in the notification bar. I am not getting a proper solution over the internet that makes sense. I need help to solve the problem.

code:

    @Override
public void onSensorChanged(SensorEvent event) {

    if (event.sensor.getType() == Sensor.TYPE_LIGHT) {
        LightSensorXvalue.setText(String.valueOf(event.values[0]));
        LightSensorYvalue.setText(String.valueOf(event.values[1]));
        LightSensorZvalue.setText(String.valueOf(event.values[2]));


    }
    if (event.sensor.getType() == Sensor.TYPE_GYROSCOPE) {
        PorximitySensorXvalue.setText(String.valueOf(event.values[0]));
        PorximitySensorYvalue.setText(String.valueOf(event.values[1]));
        PorximitySensorZvalue.setText(String.valueOf(event.values[2]));

    }

    if (event.sensor.getType() == Sensor.TYPE_ACCELEROMETER) {
        AccelerometerXvalue.setText(String.valueOf(event.values[0]));
        AccelerometerYvalue.setText(String.valueOf(event.values[1]));
        AccelerometerZvalue.setText(String.valueOf(event.values[2]));

    }

    if (event.sensor.getType() == Sensor.TYPE_GYROSCOPE) {
        gyroscopeXvalue.setText(String.valueOf(event.values[0]));
        gyroscopeYvalue.setText(String.valueOf(event.values[1]));
        gyroscopeZvalue.setText(String.valueOf(event.values[2]));
    }

}

Upvotes: 0

Views: 140

Answers (1)

emandt
emandt

Reputation: 2736

Upvotes: 0

Related Questions