Container API example


The index.html file containing JavaScript that makes use of the Container API functionality is listed below.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
<!DOCTYPE html>
<html manifest="manifest.appcache">
  <head>
    <title>Container lifecycle API usage example</title>
    <script type="text/javascript">
      var loaded = false;
      window.onLaunchboxLoaded = function () {
        loaded = true;
        initListeners();
      }
 
      function initListeners(){
        if(!loaded) {
          alert("launchbox is not yet loaded");
          return;
        }
        launchbox.Container.addLifecycleListener({
          onShow: function() {
            printText("onShow callback");
          },
          onHide: function() {
            printText("onHide callback");
          },
          onPause: function() {
            printText("onPause callback");
          },
          onResume: function() {
            printText("onResume callback");
          }
        });
      }
 
      function getID(){
        launchbox.Container.getPlatformSpecificDeviceId("androidid",
          function callback(id){
          printText(id);
          }
        );
      }
 
      function printText(str) {
        var d = document.getElementById('text-box');
        d.appendChild(document.createTextNode(str));
        d.appendChild(document.createElement('br'));
        d.scrollTop = d.scrollHeight;
      }
      function clearOutput(){
        var d = document.getElementById('text-box');
        d.innerHTML = "";
      }
 
    </script>
  </head>
  <body>
    <header>
      <h3>Container lifecycle API usage example</h3>
    </header>
    <div>
      <input type="button" onclick="getID();" value="Get device ID"/>
      <input type="button" onclick="clearOutput();" value="Clear output"/>
      <input type="button" onclick="closeApp();" value="Close an application"/>
    </div>
    <hr />
     
    <div id="text-box">
    </div>
  </body>
</html>

The contents of the cache manifest file called manifest.appcache for this application are listed below:

1
2
3
4
5
6
7
CACHE MANIFEST
 
CACHE:
index.html
 
NETWORK:
*

The webapp-descriptor.xml file for this application is defined in the following way: Notice the declaration of the appkey parameter which is required to be able to communicate with Pega AMP backend.

1
2
3
4
5
6
7
8
<?xml version="1.0" encoding="UTF-8"?>
<webapp-descriptor xmlns="http://www.pega.com/application-hosting/
web-app-descriptor/2.1">
    <id>com.pega.sample.Container</id>
    <version>1.0.0</version>
    <name>Container API usage example</name>
    <appkey>abc89755-4477-4e60-80a5-9794c6cec78e</appkey>
</webapp-descriptor>

Related topics

Public API reference
Container
Legal notice | Copyright © 2015 and Confidential to Pegasystems Inc. All rights reserved. | Feedback
Advanced...