Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

A generic sensor name

Is there a way to get a generic name of a sensor? At the moment my application lets the user select a sensor from a listview. Depending on the sensor the application should do various things.

I've tried to do this with a switch case statement and using the name of the sensor as a parameter. But since the sensor names are specific to my phone model the cases wouldn't work on other phones.

For example the "SAMSUNG Significant Motion Sensor" won't trigger a Motion sensor in a nexus phone.

I've tried to use getType(), to get the type of the sensor. But not all the sensors has a type.

My question is therefor: Is there a way to get a sensor's name that would work on all phones?

switch(sensorName){
        case "K330 3-axis Accelerometer":
            Toast.makeText(getActivity(),"Case 1: "+ sensorName, Toast.LENGTH_SHORT).show();
            break;
        case "YAS532 Magnetic Sensor":
            Toast.makeText(getActivity(), "Case 2: "+sensorName, Toast.LENGTH_SHORT).show();
            break;
        case "K330 Gyroscope sensor":
            Toast.makeText(getActivity(),"Case 3: "+ sensorName, Toast.LENGTH_SHORT).show();
            break;
        case "Barometer Sensor":
            break;
        case "MAX88920 Proximity Sensor":
            break;
        case "CM3323 RGB Sensor":
            break;
        case "SAMSUNG Significant Motion Sensor":
            break;
        default:
            break;
    }
like image 291
Amar Avatar asked Feb 28 '26 02:02

Amar


1 Answers

You can try to just check if the sensorName contains buzzwords like "Accelerometer", "Motion Sensor" etc.

if(sensorName.contains("Accelerometer")) { 
    //do stuff
} else if(sensorName.contains("Motion Sensor")) { 
    //do stuff
}
like image 97
IIIIIIIIIIIIIIIIIIIIII Avatar answered Mar 01 '26 15:03

IIIIIIIIIIIIIIIIIIIIII



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!