Implementing PhoneGap

The recommended methods of implementing PhoneGap are to use the AppFramework, or to load PhoneGap in the same way as the Apache Cordova installation does.

To use the same HTML for every platform, include the Cordova files as javascript files, then dynamically load that code based on the platform that is running. The Cordova files are packaged in the SMP_HOME\UnwiredPlatform\MobileSDKversion\HybridApp\Containers\Platform directories.

function loadPhoneGap() { 
var jsfile = null; 
var pre = "";
var language = hwc.getURLParam("lang"); 
if (!(language === undefined) && (language.length > 0)){ 
pre = "../"; 
}    
if (hwc.isAndroid()) { 
jsfile = pre + "js/android/cordova-2.0.0.javascript"; 
} 
else if (hwc.isIOS()) { 
jsfile = pre + "js/ios/cordova-2.0.0.javascript"; 
} 
else if (hwc.isBlackBerry()) {
jsfile = pre + "js/blackberry/cordova-2.0.0.javascript"; 
}    
if (jsfile) { 
var req = null; 
if (window.XMLHttpRequest) { 
req = new XMLHttpRequest(); 
} 
else {// code for IE6, IE5 
req = new ActiveXObject("Microsoft.XMLHTTP"); 
} 
req.open("GET", jsfile, false);
req.send(null);
// Need to call eval with the global context 
window[ "eval" ].call( window, req.responseText ); 
} 
}    
loadPhoneGap(); 

Initializing PhoneGap for Storage Methods

If your application calls a storage function (hwc.SUPStorage or hwc.SharedStorage, the PhoneGap must have been initialized first. If you generate your application in the Hybrid App Designer, the application detects the initialization automatically. However, if you do not generate your application using Designer, you must add code to recognize when PhoneGap is initialized.

For example, in Custom.js, add this code: