Intents
Intents are messaging objects used to start activities. An activity represents a single screen in an application. PTV Navigator supports intents for triggering different actions. An intent targeted to PTV Navigator starts the Navigator if it is not already running, brings it to the foreground and switches the Navigator to the intro screen. A currently running navigation will be cancelled.
An Intent object contains information about what activity to start and additional instructions about how this activity should perform an action. The following information is used to define an Intent:
-
Component name
The name of the component (i.e. an activity) to start. The component name is optional. If you define an component name, only the application component defined will process the Intent. If you do not define a component name, the operating system decides which application component should receive the Intent. Usually you will get a dialog containing a list of applications that are able to process the Intent.
-
Action
A string that specifies the generic action to perform. Defining an action is not necessary for PTV Navigator.
-
Data
The URI that references the data to process and the MIME type of the data.
-
Category
A string containing additional information about the kind of component that should handle the intent. Defining a category is not necessary for PTV Navigator.
-
Extras
Key-Value pairs carrying additional information for processing the rrquested action. Defining extras is currently not necessary for PTV Navigator.
-
Flags
Flags act as metadata for the Intent. They may instruct the opertaing system how to launch an activity and how to treat it after it has been launched.
Building and Sending an Intent
Using an Intent for PTV Navigator is absolutely straightforward. Just create the Intent object and pass the URI in the constructor, add some flags and send the Intent:
// Create a string containing the Intents URI String uri = "google.navigation:49.02,8.44"; // Create the Intent. // As an action, we define ACTION_VIEW, because the targeted activity should show something to the user. // As the URI, we pass the parsed uri string. Intent intent = new Intent(android.content.Intent.ACTION_VIEW, Uri.parse(uri)); // We add a flag so that the targeted activity will be brought to the front of its task's history stack if it is already running. intent.addFlags(Intent.FLAG_ACTIVITY_REORDER_TO_FRONT); // We add another flag so that the targeted activity will become the start of a new task on this history stack. intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); // This flag should also be set, to clear the targeted activity intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK); // Now simply send the Intent and start the targeted activity startActivity(intent);
Supported intents
The follwing Intents are supported by PTV Navigator. You can use them like in the example above, you only have to define the URI as described in each Intent.
-
Start Navigation by providing a position with a Geo Intent
The data URI has to be in the following format:
geo:<latitude>,<longitude>
orgeo:0,0?q=<latitude>,<longitude>(<label>)
<latitude>
The geodecimal latitude as floating point type<longitude>
The geodecimal longitude as floating point type<label>
The name unde which the destination will be saved under "Previous destinations".Code example:
double latitude = 49.022308; double longitude = 8.446573; String uri = "geo:0,0?q="+ latitude + "," + longitude;
-
Start Navigation by providing a position with a Google navigation Intent
The data URI has to be in the following format:
google.navigation:<latitude>,<longitude>?<someOptionalStuff>
orgoogle.navigation:q=<latitude>,<longitude>?<someOptionalStuff>
<latitude>
is the geodecimal latitude as floating point type<longitude>
is the geodecimal longitude as floating point type<someOptionalStuff>
is ignored by PTV NavigatorCode example:
double latitude = 49.022308; double longitude = 8.446573; String uri = "google.navigation:"+ latitude + "," + longitude;
-
Start Navigation by providing a position with a http navigation Intent
The data URI has to be in the following format:
http://maps.google.com/maps?daddr=<latitude>,<longitude>&<someOptionalStuff>
<latitude>
is the geodecimal latitude as floating point type<longitude>
is the geodecimal longitude as floating point type<someOptionalStuff>
is ignored by PTV NavigatorCode example:
double latitude = 49.022308; double longitude = 8.446573; String uri = "http://maps.google.com/maps?saddr=49.0,8.4&daddr="+ latitude + "," + longitude;
-
Start Navigation by providing an address with a Geo Intent
The data URI has to be in the following format:
geo:0,0?q=<countrycode>,<postcode>,<town>,<street>,<housenumber>
<countrycode>
The country code string as the international country symbol or as the 2 character ISO 3166-2 code.<postcode>
The post code string. This field is optional, partial post codes are supported.<town>
The town name string. This field is optional, partial and substrings are supported.<street>
The street name string. This field is optional, partial and substrings are supported.<housenumber>
The house number string. This field is optional, only numerical house numbers are supported.The address string has to contain always four commas for seperating the single address criterias, even if you leave out single criterias. For example:
D,,Karlsruhe,Haid-und-Neu-Straße,
. The more precise you specify the address, the more likely it is that you will be navigated to the correct address. Imprecise address definitions (like incomplete post code, only the first characters of a street name, ...) will be matched to the first possible target that comes along. If geocoding of the given address is not possible, the PTV Navigator will show an appropriate notice dialog.Code example:
- Start TourString address = "DE,76131,Karlsruhe,Haid,15"; String uri = "geo:0,0?q=" + address;
This Intent loads a given BCR file and fills the target station vector with the stations found in the BCR. The visited flags of the target stations will also be set as found. After this was successful, the user will be asked if he likes to navigate the tour.
The data URI has to be in the following format:
file:<filename>
<filename>
The file name of the BCR file on the Android device including an absolute path.The file has to exist in the Android file system and has to be a valid BCR file. Otherwise this Intent won't do anything.
If a file with the same name exists already, the user will be asked, if the file should be overwritten. This behaviour can be changed by setting the preference key "bcr_show_already_exists_dialog" in the navigator app to 'false'.
Code example:
String fileName = "/storage/emulated/0/tour.bcr"; String uri = "file://" + fileName; Intent intent = new Intent(android.content.Intent.ACTION_VIEW, Uri.parse(uri)); intent.addFlags(Intent.FLAG_ACTIVITY_REORDER_TO_FRONT); intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);