This first group of application services includes a core set of applications that provide basic functions for web browsing, phone calls, maps, camera, and photos. The browser will be used first, with an example using the News application, followed by brief descriptions of the other applications and how you call them from within your application.
Earlier, a WebView widget was used to display the source URL for the News story, but launching the web browser application in a new card gives more flexibility to News. The browser application can be launched to its default launch view or to a specific URL.
News will launch the browser to load a specified URL as a simple
example of an application service. The WebView widget in News is replaced with a call to
the Application Manager to launch the browser into a separate card.
The command handler for do-webStory
in the storyView-assistant.js is
replaced with a new version that includes a single call to this.controller.serviceRequest
, with the
service name set to the Application Manager, or palm://com.palm.applicationManager
. All
Application Manager calls will start this way.
The second argument is an object literal that includes an
open
method and a parameters
object that
includes the application id
property set to com.palm.app.browser
, the browser’s
application ID, and a params
object. The
params
object includes just the
target
URL retrieved from the story
array entry. This is typical of an Application Manager open
call and is used with most applications
that can accept a URL parameter:
case "do-webStory": this.controller.serviceRequest("palm://com.palm.applicationManager", { method: "open", parameters: { id: "com.palm.app.browser", params: { target: this.storyFeed.stories[this.storyIndex].url } } });
This change means that when the user taps a new Command menu
button in the storyView
scene,
the browser will launch in a separate card with the contents of the
story’s originating URL displayed. You can find the code sample for
the Command menu button changes in the section Email and Messaging.
This also eliminates the storyWeb
scene, so
you can remove the assistant and views from the News project and from
sources.json.
The user must tap the dial button to approve any phone call that is placed. Your application can initiate the phone call by opening the Phone application, providing a dial string (as shown in Figure 8-1). The phone will be launched to the dial scene, with or without the dial string included:
this.controller.serviceRequest("palm://com.palm.applicationManager", { method: "open", parameters: { target: "tel://4085556666" } } });
From within your application, you can turn on the camera and present a simple interface to take pictures, with an option to save or delete the picture after it is captured. When called from within another application, the camera application will only take a single picture and will return a file reference to the calling application if the picture was saved.
You must use a Cross-App launch to call the Camera from your
application. This requires that you call the pushScene()
method just as with any scene
push, but include scene arguments that indicate an application launch is
required:
this.someAssistant.stageController.pushScene( { appId : "com.palm.app.camera", name: "capture" }, { sublaunch : true } );
When the picture is taken or canceled, control will be returned
back to your scene with a call to the scene’s activate()
method, just as with any scene pop.
However, unlike the typical scene lifecycle, there will be a response
object passed as an argument to the activate()
method:
CameraAssistant.prototype.activate = function(response){ if (response) { if (response.returnValue) { this.showDialogBox("Picture Taken", response.filename); } else { this.showDialogBox("No Picture", ""); } } else { Mojo.Log.info("Picture not requested"); } };
The Photos application is limited to launching the application to the default view, where the user can choose between various albums and photos. All images stored on the device will be indexed and viewed this way:
this.controller.serviceRequest("palm://com.palm.applicationManager", { method: "launch", parameters: { id:"com.palm.app.photos", params: {} } } });
You can use the Maps application to display maps around specific locations defined by street address, latitude/longitude, or through a location query. The map can optionally include driving directions or additional local or business search results, and there is a choice of map type and zoom level:
this.controller.serviceRequest("palm://com.palm.applicationManager", { method: "launch", parameters: { id: "com.palm.app.maps", params: { location: {lat: 37.759568992305134, lng: −122.39842414855957, acc: 1}, query: "Pizza", } } });
This example launches the Map application to show the pizza options around a section of San Francisco with an accuracy of a meter. This is very powerful when used with the Location service, which will be covered in the next chapter.
18.191.139.245