Problem Showing Sensors Details
Posted
by Skatephone
on Stack Overflow
See other posts from Stack Overflow
or by Skatephone
Published on 2010-05-26T09:47:59Z
Indexed on
2010/06/02
14:24 UTC
Read the original article
Hit count: 380
android-sdk
|sensor
Hi, i'm looking to show detail about sensors in an Actvity but when i put my app in to my phone i manage to view only details about the accellerometer, but the program says that i have 4 sensors: Accellerometer, Magnetic field, Orientation and Temperature.
I'm using Android 1.6 and a htc Tattoo for testing.
This is my code:
public class SensorInfo extends Activity {
private SensorManager mSensorManager;
TextView mTextAcc,mTextGyr,mTextLig,mTextMag,mTextOri,
mTextPre,mTextPro,mTextTem,
mSensorsTotTitle,mSensorAvailablesTitle,mTextAccTitle,mTextGyrTitle,mTextLigTitle,mTextMagTitle,mTextOriTitle,
mTextPreTitle,mTextProTitle,mTextTemTitle;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.detaillayout);
// Get the texts fields of the layout and setup to invisible
setTextViews();
// Get the SensorManager
mSensorManager= (SensorManager) getSystemService(SENSOR_SERVICE);
// List of Sensors Available
List<Sensor> msensorList = mSensorManager.getSensorList(Sensor.TYPE_ALL);
// Print Sensor Details
Sensor sens;
int type,i;
String text = new String("");
// Do the list of available sensors on a String and print detail about each sensor
for (i=0;i<msensorList.size();i++){
sens = msensorList.get(i);
type = sens.getType();
text = " - "+getString(R.string.power)+" "+String.valueOf(sens.getPower())+"mA\n";
text+= " - "+getString(R.string.resolution)+" "+String.valueOf(sens.getResolution())+"\n";
text+= " - "+getString(R.string.maxrange)+" "+String.valueOf(sens.getMaximumRange ())+"\n";
text+= " - "+getString(R.string.vendor)+" "+sens.getVendor()+"\n";
text+= " - "+getString(R.string.version)+" "+String.valueOf(sens.getVersion());
switch(type) { // Check the type of Sensor that generate the event and show is resolution
case Sensor.TYPE_ACCELEROMETER:
mTextAccTitle.setVisibility(0);
mTextAccTitle.setMaxHeight(30);
mTextAcc.setVisibility(0);
mTextAcc.setMaxHeight(100);
mTextAcc.setText(text); // Print data of the Sensor
break;
case Sensor.TYPE_GYROSCOPE:
mTextGyrTitle.setVisibility(0);
mTextGyr.setVisibility(0);
mTextGyr.setText(text); // Print data of the Sensor
break;
case Sensor.TYPE_LIGHT:
mTextLigTitle.setVisibility(0);
mTextLig.setVisibility(0);
mTextLig.setText(text); // Print data of the Sensor
break;
case Sensor.TYPE_MAGNETIC_FIELD:
mTextMagTitle.setVisibility(0);
mTextMag.setVisibility(0);
mTextMag.setText(text); // Print data of the Sensor
break;
case Sensor.TYPE_ORIENTATION:
mTextOriTitle.setVisibility(0);
mTextOri.setVisibility(0);
mTextOri.setText(text); // Print data of the Sensor
break;
case Sensor.TYPE_PRESSURE:
mTextPreTitle.setVisibility(0);
mTextPre.setVisibility(0);
mTextPre.setText(text); // Print data of the Sensor
break;
case Sensor.TYPE_PROXIMITY:
mTextProTitle.setVisibility(0);
mTextPro.setVisibility(0);
mTextPro.setText(text); // Print data of the Sensor
break;
case Sensor.TYPE_TEMPERATURE:
mTextTemTitle.setVisibility(0);
mTextTem.setVisibility(0);
mTextTem.setText(text); // Print data of the Sensor
break;
}
}
}
// Get the texts fields of the layout and setup to invisible
void setTextViews(){
mTextAccTitle = (TextView) findViewById(R.id.sensorAccTitle);
mTextAccTitle.setVisibility(4);
mTextAccTitle.setMaxHeight(0);
mTextAcc = (TextView) findViewById(R.id.sensorAcc);
mTextAcc.setMaxHeight(0);
mTextAcc.setVisibility(4);
mTextGyrTitle = (TextView) findViewById(R.id.sensorGyrTitle);
mTextGyrTitle.setVisibility(4);
mTextGyrTitle.setMaxHeight(0);
mTextGyr = (TextView) findViewById(R.id.sensorGyr);
mTextGyr.setVisibility(4);
mTextGyrTitle.setMaxHeight(0);
mTextLigTitle = (TextView) findViewById(R.id.sensorLigTitle);
mTextLigTitle.setVisibility(4);
mTextLigTitle.setMaxHeight(0);
mTextLig = (TextView) findViewById(R.id.sensorLig);
mTextLig.setVisibility(4);
mTextLig.setMaxHeight(0);
mTextMagTitle = (TextView) findViewById(R.id.sensorMagTitle);
mTextMagTitle.setVisibility(4);
mTextMagTitle.setMaxHeight(0);
mTextMag = (TextView) findViewById(R.id.sensorMag);
mTextMag.setVisibility(4);
mTextMag.setMaxHeight(0);
mTextOriTitle = (TextView) findViewById(R.id.sensorOriTitle);
mTextOriTitle.setVisibility(4);
mTextOriTitle.setMaxHeight(0);
mTextOri = (TextView) findViewById(R.id.sensorOri);
mTextOri.setVisibility(4);
mTextOri.setMaxHeight(0);
mTextPreTitle = (TextView) findViewById(R.id.sensorPreTitle);
mTextPreTitle.setVisibility(4);
mTextPreTitle.setMaxHeight(0);
mTextPre = (TextView) findViewById(R.id.sensorPre);
mTextPre.setVisibility(4);
mTextPre.setMaxHeight(0);
mTextProTitle = (TextView) findViewById(R.id.sensorProTitle);
mTextProTitle.setVisibility(4);
mTextProTitle.setMaxHeight(0);
mTextPro = (TextView) findViewById(R.id.sensorPro);
mTextPro.setVisibility(4);
mTextPro.setMaxHeight(0);
mTextTemTitle = (TextView) findViewById(R.id.sensorTemTitle);
mTextTemTitle.setVisibility(4);
mTextTemTitle.setMaxHeight(0);
mTextTem = (TextView) findViewById(R.id.sensorTem);
mTextTem.setVisibility(4);
mTextTem.setMaxHeight(0);
}
}
Tank's Valerio From Italy
© Stack Overflow or respective owner