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;
}
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
}