Problem SDK1.5

Common bugs/problems with the Android SDK the Emulator and the ADT-Plugin.

Problem SDK1.5

Postby doubleslash » Fri May 08, 2009 8:57 pm

I cannot use the sensor methods in the new SDK1.5. I installed eclipse adt 0.9 and set it to compile against the 1.5 sdk. I'm trying to access the accelerometer in my code as follows:
Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1. class mActivity extends Activity{
  2.  
  3. SensorManager sm  = (SensorManager)getSystemService
  4.  
  5. (Context.SENSOR_SERVICE);
  6.  
  7. sm.registerListener(new MyListener(), Sensor.TYPE_ACCELEROMETER,
  8.  
  9. SensorManager.SENSOR_DELAY_UI);
  10.  
  11.  
  12.  
  13.  
  14.  
  15. class MyListener implements SensorEventListener{
  16.  
  17. // implementation is irrelevant
  18.  
  19.  
  20.  
  21. }
  22.  
  23. }
  24.  
  25.  
Parsed in 0.030 seconds, using GeSHi 1.0.8.4
I have a build error that I should change MyListener to type SensorListener, which has been deprecated in the new SDK. I'm confused why it wants me to use an interface that is no longer supported.
Thanks for any help.
doubleslash
Developer
Developer
 
Posts: 30
Joined: Fri Feb 13, 2009 6:05 am

Top

Postby neskal » Thu May 21, 2009 2:26 pm

Problem is with Sensor.TYPE_ACCELEROMETER -it's int while you need Sensor there. Use sm.getDefaultSensor(Sensor.TYPE_ACCELEROMETER) instead. Try this
Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1.  
  2. class mActivity extends Activity{
  3.  
  4. SensorManager sm  = (SensorManager)getSystemService
  5.  
  6. (Context.SENSOR_SERVICE);
  7.  
  8. sm.registerListener(new MyListener(), sm.getDefaultSensor(Sensor.TYPE_ACCELEROMETER) ,
  9.  
  10. SensorManager.SENSOR_DELAY_UI);
  11.  
  12.  
  13.  
  14.  
  15.  
  16. class MyListener implements SensorEventListener{
  17.  
  18. // implementation is irrelevant
  19.  
  20.  
  21.  
  22. }
Parsed in 0.032 seconds, using GeSHi 1.0.8.4

}
neskal
Once Poster
Once Poster
 
Posts: 1
Joined: Wed May 20, 2009 10:27 pm

Postby doubleslash » Thu May 21, 2009 3:41 pm

Thanks, that does it. I looked at the documentation today, and apparently the version I was using has been deprecated.
doubleslash
Developer
Developer
 
Posts: 30
Joined: Fri Feb 13, 2009 6:05 am

Top

Return to SDK/ADT/Emulator Problems

Who is online

Users browsing this forum: Yahoo [Bot] and 5 guests