I write solutions to the problems I can't find much about elsewhere on the Web, also some code/script snippets that are absolutely awesome and make my life easier. Will be glad if someone finds these posts interesting and helpful!

Friday, April 29, 2011

Android universal Intent to start a "navigation activity"

The mission is what the title says. It was quite hard to define the problem to search for a solution. I ended up asking for help at StackOverflow and as I was suggested, I implemented a way to list some known apps and let the user select a preferred nav app.

So, let's say, somewhere on Activity there's a button, which on click is supposed to call the Navigation application. The way I did it, on tap, the activity shows a custom dialog letting the user select one of the known applications or prompt Android to find suitable activities implicitly.

Here's the source code of the payload of the main method invoked from the OnClickListener - showNavigation():


Here are few utils needed only to follow up the last call in the showNavigation() method - showTableDialog():


These are the resource files:
* this goes to /res/values/themes.xml

* this goes to /res/values/styles.xml

* this goes to /res/layout/table_dialog.xml

* this goes to /res/drawable as menu_gps.png







And here is the result dialog you are supposed to see:

On click on each row it will start up the respective activity.
That's it, I hope it helps!

2 comments:

  1. Very nice!

    But your code will serve to start a turn by turn Navigator withour any destination set, correct?

    Do you know any way to start turn-by-turn Navigation to a specified lat/long coordinates? I wonder if this is possible with NDrive for example.

    ReplyDelete
  2. @Fede, that's right, without destination. The only navigator I know of which supports destination (it supports a public Intent and accepts parameters) is Navigon. That's the reason why it's the only one with 'new Intent' statement in the list of navigators.

    ReplyDelete