views:

528

answers:

1

I cannot find any tutorial on the web. How can I do it in a simple way?

A: 

That of course depends on what you want your compass to show, i.e. how it is supposed to figure out the current heading.

There are at least two possible solutions:

  1. Use a hardware compass sensor, if the host device has one. Not sure if all Android phones have this.
  2. Use GPS positioning data; since GPS tracks position, you will need to have some movement to extrapolate a direction, and it will be coarse. You can't spin in place and have the compass update.

You should probably look at the LocationProvider API, it has a method called supportsBearing() that sounds like a good first step.

unwind