• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

G1 Magnetic Detection

 
Ryan Waggoner
Ranch Hand
Posts: 75
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hey guys,
This post might be too much about the G1 but...

I still get excited when I find out the phone can still do cool things. For example the compass works with real magnetic fields. I was wondering where i could find information to see how this works, and how to harness the data...

Just to play with it really

Thanks!
 
Jake Reynolds
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Wow, that's cool! Anyone know of it's subject to the same acceleration and turning errors a wet compass is? I've got to get my hands on a G1 to test it out.
 
Nenad Nikolic
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ryan Waggoner wrote:Hey guys,
This post might be too much about the G1 but...

I still get excited when I find out the phone can still do cool things. For example the compass works with real magnetic fields. I was wondering where i could find information to see how this works, and how to harness the data...

Just to play with it really

Thanks!


Hi Ryan,

You would need to use android.hardware.SensorManager class and android.hardware.SensorListener interface to read magnetic values.

Start with the Compass example (via this link copy-pasted here for your convenience):

You would need to change this particular example (line 69) to read magnetic field data instead of orientation data:

Continue experimenting from there in the vicinity of sources of magnetic fields in your house - other mobile phones, TV, microwave (but don't put your Android inside!) etc.

I hope that helps.

BTW, did you know Android SDK developers even made it easier for you to develop a Star Wars games.
There's a constant is in SDK: android.hardware.SensorManager.GRAVITY_DEATH_STAR_I :-)

Cheers!
Shonzilla
 
Monu Tripathi
Rancher
Posts: 1369
1
Android Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The API(SensorManager) class has constants for 11 different sensors(If i remember correctly). Accelerometer, Orientation Sensor, Temperature sensor, Magnetic sensor etc.
Different devices will support(or will be built with) different sensors, I think. It surely sounds cool.
 
Ryan Waggoner
Ranch Hand
Posts: 75
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Very Cool!

Thanks a lot for the info and example
 
Michael Rivera
Ranch Hand
Posts: 129
Android Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Nice code there, sure thing that Android supports all of these and hope more awesome stuff will be pushed to the SDK!
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic