Client API
Using the HP Anywhere client application, end users can access your apps on their devices. You can use any JavaScript framework to implement the client, such as jQuery Mobile or AngularJS.
Every time a user opens your app, the HP Anywhere framework allocates a new app instance. Each app instance resides in its own HTML IFrame. This ensures that each app instance is resource-independent in relation to other app instances.
For an app to run successfully, its client-related resources and dependencies (mostly JavaScript and CSS files) need to be downloaded to the user’s device. To enable the HP Anywhere framework to do this automatically, you must declare these resources and dependencies in the app’s descriptor file.
Note: To improve performance, it is recommended that you compile all your JavaScript and CSS resource files into a single, minified resource.
To take advantage of the capabilities provided by the HP Anywhere framework, such as opening your app from HP Anywhere and enabling user collaboration, your app must communicate with the HP Anywhere framework via HP Anywhere’s pure JavaScript API. To do this, the HP Anywhere framework injects a set of JavaScript APIs that the app can use. For example:
// this pops up a message with the logged in user’s name
HPA.Message.info( "Hello, " + HPA.Profile.getInfo().displayName);
What does my app need to implement?
Your app must call HPA.Framework.setReady(True) after the resources and code of your app load. This notifies the HP Anywhere Framework that your app is loaded and is ready to process entry point requests.
Your app must also contain the top-level function, openEntryPoint, which is the starting point through which the framework directs entry point requests and notifications to the app. The HP Anywhere framework calls this function at least once when your app starts. (This function is not to be confused with the openEntryPoint method, which can be called by your app to open a specific app page.)
In the openEntryPoint (entryPointName, params, callback, scope) function, the first argument, 'entryPointName', is mandatory. 'Params', 'callback', and 'scope' are optional. A typical implementation of this function includes a switch statement on the given entry point, with a case clause for each possible entry point name. For example:
function openEntryPoint(entryPoint, params, callback, scope) { console.log('Entry Point : ' + entryPoint + ' was called'); console.log('params: ', params); switch (entryPoint) { case "SummaryEntryPoint": this.summary(); break; case 'DOCUMENTS_LIST': this.main(); break; case 'OpenEntryPoint': this.main(params); break; default: } return true; }
The HPA.Framework API contains several important methods that your app can use to interact with the HP Anywhere framework.
For more details and useful recipes, see HP Anywhere Events Sample App Cookbook.
HP Anywhere Client Objects
HP Anywhere places collaboration at the heart of any successful workflow by combining structured processes with unstructured discussions into organized, context-specific activity streams. An activity is a centralized entity that enables multiple participants to collaborate, consume relevant information, and perform tasks relevant to their day-to-day job in the organization. For more details, see the HP Anywhere User Guide.
Activities can contain context objects and entry point objects.
Context objects
A context object represents a business entity, such as a report or a defect. Each context object contains the following properties:
- An object ID (objectId), which is a globally unique identifier that identifies the context object in the HP Anywhere database.
- A data type (dataType), which specifies the type of data, such as a report, an expense, or a defect. Your app can display this data in the HP Anywhere client, for example, in the list of context objects, and your app code can use this data, as needed.
- A display name (displayName), which is the name of context object as displayed in the app.
- Optional extended data (metaData) that you can add if you want additional, persistent data in the app code. For example, you may want to add the internal ID of the business entity to enable your app to fetch data from your system’s backend.
Use case scenarios
Open an app instance
When a user opens your app, the client retrieves a list of any context objects that are contained in the current activity, and the app opens at the top-level entry point. You add this call using the openEntryPoint function described above.
Create a context object and add it to an activity
Before you can add a context object to an activity, you create it using the createContextObject method. This method uses the parameters described for context objects, above.
After you create the context object, you validate it using isValidContextObject utility method to ensure that it is suitable for the HPA framework. This method returns a Boolean value. If the context object is not valid, you can use the validateContextObject to obtain detailed information explaining why.
Finally, you add the context object to an activity using the addContextObjectToActivity method.
Set the current context for an app
To improve collaboration between users, your app can automatically add the current context object to an activity. For example, you may want to automatically add a specific context object when a participant is added to an activity or when a user adds a post in the Timeline. You do this by calling the setCurrentContext method.
Entry point objects
An entry point object represents a specific page in an app, such as the landing page.
Each entry point object contains:
- An app ID (appId), which is a globally unique identifier that identifies the app containing the entry point.
- An entry point ID (entryPoint), which specifies the app page to open when a user performs an action, such as clicking a link.
- A display name (displayName), which is the name of entry point object as displayed in the activity’s list of the context objects.
Use case scenario
Create an entry point object for an app
You can create an entry point object to use, for example, before setting the current context of your app. You do this by calling the createEntryPointObject method. This method uses the parameters described for entry point objects, above.
Using a device’s native capabilities
The HP Anywhere client allows your app to access commonly used, out-of-the-box PhoneGap plugins, such as Camera, Contacts, Device, File, Events, Geolocation, InAppBrowser, Notification, and Storage. To do this, you add a window.parent prefix to your code.
Example 1:
The following example illustrates how to enable your app to take a photograph using the device’s built-in camera. To do this, you add a window.parent prefix to your code.
var success = function (fileURI) { // do something with the photo . . . }), failure = function () { // handle failure. . . }; var camOptions = { quality: 50, destinationType: window.parent.Camera.DestinationType.FILE_URI, encodingType: window.parent.Camera.EncodingType.JPEG, allowEdit: true, targetWidth: 320, targetHeight: 480 }; window.parent.navigator.camera.getPicture(success, failure, camOptions);
Example 2:
This example shows how to add a barcode scanner to your app using the device’s built-in camera.
The code uses the scan (success, fail)
method, where success
and fail
are callback functions.
window.parent.cordova.plugins.barcodeScanner.scan( function (result) { console.log("We got a barcode\n" + "Data: " + result.text + "\n" + // A textual representation of the barcode data. "Type: " + result.format + "\n" + // The type of barcode. See below for possible types. "Cancelled: " + result.cancelled); // Specifies whether the user cancelled the scan. }, function (error) { console.log("Scanning failed: " + error); } );
Supported Barcode Types
Android
QR_CODE | DATA_MATRIX | UPC_A | EAN_8 | EAN_13 |
CODE_128 | CODE_39 | CODE_93 | CODABAR | ITF |
iOS
QR_CODE | DATA_MATRIX | UPC_A | EAN_8 | EAN_13 | CODE_128 |
For more details on PhoneGap, see phonegap.com. (At the time of this writing, PhoneGap version is 3.0.0.)
Adding a link directly to your app
You can generate direct links to your app that, when clicked, open your app directly in the HP Anywhere client on an end user’s device.
This lets you send links to your app via email, SMS, or include a link to your app from a Web page.
You create these links using the following format: hpanywhere://openApp/[TARGET-APP-ID]