I\'m trying to display a list of available sensors but it\'s like there are not!
I was thinking that it was because of the emulator, but i tried it on the phone and the re
You can try this code:-
package com.example.sensor;
import java.util.List;
import android.content.Context;
import android.hardware.Sensor;
import android.hardware.SensorManager;
import android.os.Bundle;
import android.support.v7.app.ActionBarActivity;
import android.widget.ArrayAdapter;
import android.widget.ListView;
public class MainActivity extends ActionBarActivity {
SensorManager smm;
List sensor;
ListView lv;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
smm = (SensorManager) getSystemService(Context.SENSOR_SERVICE);
lv = (ListView) findViewById (R.id.listView1);
sensor = smm.getSensorList(Sensor.TYPE_ALL);
lv.setAdapter(new ArrayAdapter(this, android.R.layout.simple_list_item_1, sensor));
}
}
Just put a list view in your xml layout.