मैं उपलब्ध सेंसर की एक सूची प्रदर्शित करने की कोशिश कर रहा हूं लेकिन ऐसा नहीं है!
मैं सोच रहा था कि यह एमुलेटर की वजह से था, लेकिन मैंने इसे फोन पर करने की कोशिश की और नतीजा वही है।एक एंड्रॉइड सेंसर सूची प्रदर्शित करें
private SensorManager mSensorManager;
TextView mSensorsTot,mSensorAvailables;
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
// Get the texts fields of the layout and setup to invisible
mSensorsTot = (TextView) findViewById(R.id.sensoritot);
mSensorAvailables = (TextView) findViewById(R.id.sensoridisponibili);
// Get the SensorManager
mSensorManager= (SensorManager) getSystemService(SENSOR_SERVICE);
// List of Sensors Available
List<Sensor> msensorList = mSensorManager.getSensorList(SensorManager.SENSOR_ALL);
// Print how may Sensors are there
mSensorsTot.setText(msensorList.size()+" "+this.getString(R.string.sensors)+"!");
// Print each Sensor available using sSensList as the String to be printed
String sSensList = new String("");
Sensor tmp;
int x,i;
for (i=0;i<msensorList.size();i++){
tmp = msensorList.get(i);
sSensList = " "+sSensList+tmp.getName(); // Add the sensor name to the string of sensors available
}
// if there are sensors available show the list
if (i>0){
sSensList = getString(R.string.sensors)+":"+sSensList;
mSensorAvailables.setText(sSensList);
}
}
काम करता है, अंगूठे ऊपर! धन्यवाद – Skatephone