Light sensor

Put your problem here if it does not fit any of the other categories.

Light sensor

Postby miecak » Sun Mar 21, 2010 8:51 pm

I started fooling around with the sensors on my HTC Magic today. But for some reason I cannot see or find the light sensor. The light sensor IS mentioned in the phones specs.

This is what I used to compose the list. Am I doing something wrong or is there something wrong with the light sensor ?

Thanks!

Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1.  
  2. public class SensorList extends Activity {
  3.  
  4.         private SensorManager sensorManager;
  5.  
  6.         private ListView myListView;
  7.  
  8.  
  9.  
  10.     @Override
  11.  
  12.     public void onCreate(Bundle savedInstanceState) {
  13.  
  14.         super.onCreate(savedInstanceState);
  15.  
  16.         setContentView(R.layout.main);
  17.  
  18.        
  19.  
  20.         //Get the sensor manager
  21.  
  22.         sensorManager = (SensorManager)getSystemService(Context.SENSOR_SERVICE);
  23.  
  24.         //Get our listView
  25.  
  26.         myListView = (ListView)findViewById(R.id.MyListView);
  27.  
  28.        
  29.  
  30.         //An ArrayList to hold the sensors in
  31.  
  32.         ArrayList<String> sensors = new ArrayList<String>();
  33.  
  34.         //ArrayAdapter to connecto to our ArrayList of sensors
  35.  
  36.         final ArrayAdapter<String> aa;
  37.  
  38.         aa = new ArrayAdapter<String>(this,android.R.layout.simple_list_item_1,sensors);
  39.  
  40.         //Set the adapter to the ListView
  41.  
  42.         myListView.setAdapter(aa);
  43.  
  44.        
  45.  
  46.         //Get a list of all the sensors
  47.  
  48.         List<Sensor> sensorList = sensorManager.getSensorList(Sensor.TYPE_ALL);
  49.  
  50.        
  51.  
  52.         //Place each sensor in our ListView
  53.  
  54.         for(int i=0;i<sensorList.size();i++){
  55.  
  56.                 sensors.add(0, sensorList.get(i).getName());            
  57.  
  58.             aa.notifyDataSetChanged();
  59.  
  60.         }
  61.  
  62.     }
  63.  
  64. }
  65.  
  66.  
Parsed in 0.036 seconds, using GeSHi 1.0.8.4
miecak
Once Poster
Once Poster
 
Posts: 1
Joined: Sun Mar 21, 2010 8:45 pm

Top

Return to Other Coding-Problems

Who is online

Users browsing this forum: No registered users and 20 guests