Service

Access device services like the accelerometer, GPS, contacts, etc.

Classes

Service.Request

Created with Service.createRequest

Service.Request Methods

Service.Request#cancel
Service.Request#cancel() -> undefined

Call this to cancel a pending request.

Class Methods

Service.createRequest

Service.createRequest(url, parameters, callback) -> Service.Request

  • url (String) – The url of the service and method to access.
  • parameters (Object) – The parameters to pass to the service. These will be serialized by the request automatically.
  • callback (Function) – The function to be called with the results of the service request.

This creates a request to the Palm Service bus. See the service documentation for more details on service APIs.

The url for a service is usually something like palm://com.palm.location. In regular Mojo, you pass a method parameter when creating a service request. In reality, that just gets tacked onto the service url. So, when using this API, the developer needs to do that concatenation himself. For example, if the developer is querying for the user's location, the URL would be palm://com.palm.location/getCurrentPosition. The parameters argument should then be a JavaScript object to be serialized and sent to the method.

Example

var request = MojoCore.Service.createRequest(
  'palm://com.palm.location/getCurrentPosition',
  {
      accuracy: 1,
      maximumAge: 0,
      responseTime: 3
  },
  function(response) {
      console.log("Latitude is: " + response.latitude);
  }
);