This guide explains the technical specifications of JSAPIs that is available to be called from your application's frontend.
Integrate SDK
-
Include the gpContainer SDK in Your Codebase
To use the SDK, add the following<script src="https://gwk.gopayapi.com/sdk/stable/gp-container.min.js"></script>
-
Invoking SDK Methods
To call any JSAPI from the SDK, use the following format:window.gpContainer.call(className, methodName, params, successCallback, failureCallback, timeout);
Supported JSAPIs
GPMiniAppAuth
API | Function | Requires Consent |
---|---|---|
GPMiniAppAuth.getAuthCode | Get an auth code used to identify the current user session | No |
GP
API | Function | Requires Consent |
---|---|---|
GP.launchPayment | Automatically redirect users to the GoPay app to complete the payment, then return them to your Mini App. | No |
GPNavigator
API | Function | Android | IOS |
---|---|---|---|
GPNavigator.launchDeeplink | Open a third-party app or page using a custom deeplink | Support | Support |
GPNavigator.launchUri | Open a browser or in-app page using a universal or web URI | Support | Support |
GPNavigator.pop | Closes the current page. | Support | Support |
GPNavigator.push | Opens a new page in the miniapp. | Support | Support |
GPMotion
API | Function | Android | IOS |
---|---|---|---|
GPMotion.listenBlow | Monitors blow gestures. | Support | Support |
GPMotion.stopListenBlow | Stops monitoring blow gestures. | Support | Support |
GPMotion.listenGyro | Enables or disables monitoring of the gyroscope. | Support | Support |
GPMotion.listeningShake | Enables or disables monitoring of shake gestures. | Support | Support |
GPMotion.vibrate | Makes the phone vibrate. | Support | Support |
GPMotion.startAccelerometer | Monitors acceleration data. | Support | Support |
GPMotion.stopAccelerometer | Stops monitoring acceleration data. | Support | Support |
GPMotion.startCompass | Monitors compass data. | Support | Support |
GPMotion.stopCompass | Stops monitoring compass data. | Support | Support |
Base
API | Function | Android | IOS |
---|---|---|---|
GPBase.copyToClipboard | Copies the specified text to the clipboard. | Support | Support |
GPBase.isInstall | Checks whether the specified app is installed. | Support | Support |
GPBase.isAppsInstalled | Checks whether the specified apps are installed. | Support | Support |
GPBase.notify | Triggers the specified event in document. | Not Support | Support |
GPBase.setBackgroundColor | Configures the background color of WebView. | Not Support | Support |
GPBase.canIUse | Checks whether an API is supported by the current WindVane SDK version. | Support | Support |
GPMiniApp.close | Closes the miniapp. | Support | Support |
Widget
API | Function | Android | IOS |
---|---|---|---|
GPUI.showLoadingBox | Displays the loading message. | Support | Support |
GPUI.hideLoadingBox | Hides the loading message. | Support | Support |
GPUI.hideKeyboard | Hides the keyboard. | Support | Support |
Prompt
API | Function | Android | IOS |
---|---|---|---|
GPUIToast.toast | Displays a toast in the center of the screen. | Support | Support |
Dialog
API | Function | Android | IOS |
---|---|---|---|
GPUIDialog.alert | Displays a warning message. | Support | Support |
GPUIDialog.confirm | Displays a confirmation message. | Support | Support |
GPUI.enableAlertBeforeUnload | Displays a confirmation message when a user attempts to close the miniapp by clicking the Back button. | Support | Support |
GPUI.disableAlertBeforeUnload | Does not display a confirmation message when a user attempts to close the miniapp by clicking the Back button. | Support | Support |
GPUIDialog.prompt | Displays a text box where a user can input text. | Support | Support |
GPUIDialog.showAuthGuide | Displays a dialog box to guide the user in granting permissions. The dialog box provides text and illustrations. | Support | Support |
Action List
API | Function | Android | IOS |
---|---|---|---|
GPUIActionSheet.show | Displays an action sheet. A list of buttons is displayed at the bottom of the screen. | Support | Support |
Navigation Bar
Multimedia
API | Function | Android | IOS |
---|---|---|---|
GPImage.saveImage | Saves images from HTTP or HTTPS URLs or Base64-encoded images to albums. | Support | Support |
GPVideo.chooseVideo | Shoots a video or selects a video from an album. | Support | Support |
GPVideo.saveVideoToPhotosAlbum | Saves an online video to a local album. | Support | Support |
GPAudio.playSystemSound | Plays the specified system sound. | Not Support | Support |
GPCamera.takePhoto | Takes a photo or selects a photo from the album. Users can determine whether to enable automatic photo upload. The automatic photo upload feature needs to be implemented in the native application. | Support | Support |
GPCamera.confirmUploadPhoto | Confirms the photo upload. | Support | Support |
Cache
API | Function | Android | IOS |
---|---|---|---|
GPStorage.setItem | Sets the value of a specified key in the local cache. | Support | Support |
GPStorage.getItem | Obtains the value of a specified key from the local cache. | Support | Support |
GPStorage.removeItem | Removes the value of a specified key from the local cache. | Support | Support |
GPStorage.clearStorage | Asynchronously clears the local data cache. | Support | Support |
GPStorage.clearStorageSync | Synchronously clears the local data cache. | Support | Support |
File
API | Function | Android | IOS |
---|---|---|---|
GPFile.write | Writes the specified content to a disk. | Support | Support |
GPFile.read | Reads the content of a specified file. | Support | Support |
GPFile.getFileInfo | Obtains information about a file. | Support | Support |
GPFile.downloadFile | Downloads a file from a specified URL. | Support | Support |
GPFile.uploadFile | Uploads a file to a specified server URL. | Support | Support |
Geographic location
API | Function | Android | IOS |
---|---|---|---|
GPLocation.getLocation | Obtains the current geographic location. (Requires Consent) | Support | Support |
GPLocation.searchLocation | Searches for the specified address and obtains the latitude and longitude. | Not Support | Support |
Cookie
System information
API | Function | Android | IOS |
---|---|---|---|
GPSystem.getSystemInfo | Obtains the system information of a device. | Support | Support |
GPSystem.getSystemInfoSync | Synchronously obtains the system information of a device. | Support | Support |
Device environment detection
API | Function | Android | IOS |
---|---|---|---|
GPNativeDetector.isSimulator | Checks whether the device is simulated. | Support | Support |
GPNativeDetector.getCurrentUsage | Obtains the current CPU utilization and memory usage. | Support | Support |
GPNativeDetector.getDeviceYear | Obtains the release year of the device. You can learn about the device performance based on its release year. You can easily identify the model of an iOS device and determine whether its performance can meet your business requirements. For an Android device, you can determine whether its performance is adequate only based on its release year. | Support | Support |
GPNativeDetector.getModelInf | Obtains the device information, such as the device model. | Support | Support |
GPNativeDetector.getSafeAreaInsets | Obtains the safe area information of the current view. This API is available only for full screen pages. | Not Support | Support |
Network status
API | Function | Android | IOS |
---|---|---|---|
GPNetwork.getNetworkType | Obtains the current network type. | Support | Support |
Screen
API | Function | Android | IOS |
---|---|---|---|
GPScreen.getOrientation | Obtains the display orientation (landscape or portrait) of the current activity or view controller. | Support | Support |
GPScreen.setOrientation | Sets the display orientation (landscape or portrait) of the current activity or view controller. | Support | Support |
GPScreen.setScreenBrightness | Sets the screen brightness. | Support | Support |
GPScreen.getScreenBrightness | Obtains the screen brightness. | Support | Support |
Screenshot
API | Function | Android | IOS |
---|---|---|---|
GPScreenCapture.capture | Takes a screenshot of the visible content in WebView. | Support | Support |
Beep
API | Function | Android | IOS |
---|---|---|---|
GPNotification.beep | Makes the phone beep. | Support | Support |
Calling
Application information
API | Function | Android | IOS |
---|---|---|---|
GPApplication.appState | Returns the status of the application. The status indicates whether the application is running in the foreground. | Not Support | Support |
GPApplication.getNotificationSettings | Returns the notification settings of the application. | Not Support | Support |
GPApplication.openSettings | Displays the settings page of the application. | Not Support | Support |
Address book
API | Function | Android | IOS |
---|---|---|---|
GPContacts.askAuth | Requests access to contacts. | Not Support | Support |
GPContacts.authStatus | Checks whether access permissions on contacts are granted. | Not Support | Support |
GPContacts.choose | Displays contacts. After a user selects a contact, the name and phone number of the contact are returned to the HTML5 page. | Support | Support |
GPContacts.find | Searches for a contact by specifying the name and phone number. | Support | Support |
GPContacts.addPhoneContacts | Adds a contact. | Support | Support |
Code scanning
API | Function | Android | IOS |
---|---|---|---|
GPScan.scan | Enables the scanning feature. | Support | Support |
Device battery
API | Function | Android | IOS |
---|---|---|---|
GPBattery.getBatteryInfo | Asynchronously obtains the battery level. | Support | Support |
GPBattery.getBatteryInfoSync | Device battery | Support | Support |
Bluetooth
API | Function | Android | IOS |
---|---|---|---|
GPBluetooth.requestAuthorization | Requests Bluetooth permissions and enables Bluetooth. | Support | Support |
GPBluetooth.scan | Searches for Bluetooth Low Energy (BLE) devices. | Support | Support |
GPBluetooth.stopScan | Stops searching for BLE devices. | Support | Support |
GPBluetooth.connect | Connects the device on which the application runs to a Bluetooth device with a specified Bluetooth address. | Support | Support |
GPBluetooth.disconnect | Disconnects the connected Bluetooth devices. | Support | Support |
GPBluetooth.getServices | Starts to search for the BLE device services. | Support | Support |
GPBluetooth.getCharacteristics | Obtains values of all characteristics of BLE devices. | Support | Support |
GPBluetooth.writeValue | Sets the value of a specified characteristic to a connected BLE device. | Support | Support |
GPBluetooth.readValue | Reads the value of a specified characteristic from a connected BLE device. | Support | Support |
GPBluetooth.startNotifications | Enables the notification of characteristic value changes. | Support | Support |
GPBluetooth.stopNotifications | Disables the notification of characteristic value changes. | Support | Support |
Communication
API | Function | Android | IOS |
---|---|---|---|
GPStandardEventCenter.postNotificationToNative | Sends events from the miniapp to a native application. The event name can be modified based on the business requirements of the native application. | Support | Support |
Other features
API | Function | Android | IOS |
---|---|---|---|
Background | When the application starts to run in the background, for example, when a user switches to another app or opens the notification bar, GoPay Container SDK triggers the GP.Event.APP.Background event. The page can listen for this event to determine whether the application switches to the background. | Support | Support |
Active | When the application switches from the background to the foreground, WindVane triggers the GP.Event.APP.Active event. The page can listen for this event to determine whether the application is active. | Support | Support |
Pull Refresh | In iOS, the pull-to-refresh feature is enabled by default. The pull-to-refresh feature is enabled by default. You must disable the feature manually. | Not Support | Support |
Infinite Scroll | Enables the infinite scrolling feature. More content is loaded when a user scrolls to the bottom of the page. Infinite scrolling is disabled by default. You must enable the feature manually. | Not Support | Support |
JSAPIs Specification (v1.0.0)
Note
- Data will be null in case of success = false, and vice versa.
- Error will be null in case of success = true, and vice versa.
Get Location
Sample Request:
var params = {
// Specify whether to obtain a high-precision location.
enable_high_accuracy: true
};
window.gpContainer.call(
"GPLocation",
"getLocation",
params,
function(response) {
console.log('success:', response);
},
function(error) {
console.log('error:', error);
}
);
Sample Response: (error codes)
{
"success": true,
"data": {
"coords": {
"longitude": 77.5946,
"latitude": 12.9716,
"time": 12
}
},
"ret": "GP_SUCCESS"
}
{
"success": false,
"errorCode": "",
"errorType": "JS_BRIDGE_ERROR",
"errorMessage": "",
"ret": "GP_EXCEPTION"
}
Get Auth Code
Sample Request:
window.gpContainer.call(
"GPMiniAppAuth",
"getAuthCode",
{},
function(response) {
console.log('success:', response);
},
function(error) {
console.log('error:', error);
}
);
Sample Response: (error codes)
{
"success": true,
"data": {
authCode: "GBNURP5WyBIqXiGxKv2cO8Qj4CyS0qZrRK5O4e8ehdnHpowG6k5pkj2SsF7BqGIF"
},
"ret": "GP_SUCCESS"
}
{
"success": false,
"errorCode": "",
"errorType": "JS_BRIDGE_ERROR",
"errorMessage": "",
"ret": "GP_EXCEPTION"
}
Launch Deeplink
Sample Request:
var params = {
deeplink: "gopay://..."
};
window.gpContainer.call(
"GPNavigator",
"launchDeeplink",
params,
function(response) {
console.log('success:', response);
},
function(error) {
console.log('error:', error);
}
);
Sample Response: (error codes)
{
success: true,
"ret": "GP_SUCCESS"
}
{
"success": false,
"errorCode": "300",
"errorType": "JS_BRIDGE_ERROR",
"errorMessage": "Permission denied",
"ret": "GP_EXCEPTION"
}
Launch Payment
Sample Request:
var params = {
deeplink: "gopay://..."
};
window.gpContainer.call(
"GP",
"launchPayment",
params,
function(response) {
console.log('success:', response);
},
function(error) {
console.log('error:', error);
}
);
Sample Response: (error codes)
{
success: true,
data: {
status: "success"
},
"ret": "GP_SUCCESS"
}
{
"success": false,
"errorCode": "300",
"errorType": "JS_BRIDGE_ERROR",
"errorMessage": "Permission denied",
"ret": "GP_EXCEPTION"
}
Status | Description |
---|---|
success | User have successfully paid the transaction |
failed | User cancelled the transaction |
pending | There's an error processing the transaction |
cancelled | User goes back to the miniapp without completing or cancelling the payment |
Launch Uri
Sample Request:
var params = {
uri: "string"
};
window.gpContainer.call(
"GPNavigator",
"launchUri",
params,
function(response) {
console.log('success:', response);
},
function(error) {
console.log('error:', error);
}
);
Sample Response: (error codes)
{
"success": true,
"ret": "GP_SUCCESS"
}
{
"success": false,
"errorCode": "300",
"errorType": "JS_BRIDGE_ERROR",
"errorMessage": "Permission denied",
"ret": "GP_EXCEPTION"
}
CopyToClipboard
Sample Request:
var params = {
text: "string"
};
window.gpContainer.call(
"GPBase",
"copyToClipboard",
params,
function(response) {
console.log('success:', response);
},
function(error) {
console.log('error:', error);
}
);
Sample Response: (error codes)
{
"success": true,
"ret": "GP_SUCCESS"
}
{
"success": false,
"errorCode": "",
"errorType": "JS_BRIDGE_ERROR",
"errorMessage": "",
"ret": "GP_EXCEPTION"
}
isInstall
Sample Request:
var params = {
// The app label that is used in iOS.
ios: 'gopay://',
// The app label that is used in Android.
android: 'com.gopay.gopay'
};
window.gpContainer.call(
"GPBase",
"isInstall",
params,
function(response) {
console.log('success:', response);
},
function(error) {
console.log('error:', error);
}
);
Sample Response: (error codes)
{
"success": true,
"ret": "GP_SUCCESS"
}
{
"success": false,
"errorCode": "",
"errorType": "JS_BRIDGE_ERROR",
"errorMessage": "",
"ret": "GP_EXCEPTION"
}
isAppsInstalled
Sample Request:
var params = {
gopay: {
ios: 'gopay://',
android: 'com.gopay.gopay'
},
gojek: {
ios: 'gojek://',
android: 'com.gojek.gojek'
}
};
window.gpContainer.call(
"GPBase",
"isAppsInstalled",
params,
function(response) {
console.log('success:', response);
},
function(error) {
console.log('error:', error);
}
);
Sample Response: (error codes)
{
"success": true,
"ret": "GP_SUCCESS"
}
{
"success": false,
"errorCode": "",
"errorType": "JS_BRIDGE_ERROR",
"errorMessage": "",
"ret": "GP_EXCEPTION"
}
notify
Sample Request:
var params = {
// The name of the event
event: 'MyNotifyName',
// The parameters of the event
param: { MyEventParam: 'paramValue'
};
window.gpContainer.call(
"GPBase",
"notify",
params,
function(response) {
console.log('success:', response);
},
function(error) {
console.log('error:', error);
}
);
document.addEventListener('MyNotifyName', function(e) {
alert(JSON.stringify(e.param));
}, false);
Sample Response: (error codes)
{
"success": true,
"ret": "GP_SUCCESS"
}
{
"success": false,
"errorCode": "",
"errorType": "JS_BRIDGE_ERROR",
"errorMessage": "",
"ret": "GP_EXCEPTION"
}
{
"success": true,
"ret": "GP_SUCCESS"
}
openBrowser
Sample Request:
var params = {
// The URL that is displayed in browser.
url: 'http://www.gopay.com'
};
window.gpContainer.call(
"GPBase",
"openBrowser",
params,
function(response) {
console.log('success:', response);
},
function(error) {
console.log('error:', error);
}
);
Sample Response: (error codes)
{
"success": true,
"ret": "GP_SUCCESS"
}
{
"success": false,
"errorCode": "",
"errorType": "JS_BRIDGE_ERROR",
"errorMessage": "",
"ret": "GP_EXCEPTION"
}
setBackgroundColor
Sample Request:
var params = {
color: 'FF0000',
alpha: 0.3
};
window.gpContainer.call(
"GPBase",
"setBackgroundColor",
params,
function(response) {
console.log('success:', response);
},
function(error) {
console.log('error:', error);
}
);
Sample Response: (error codes)
{
"success": true,
"ret": "GP_SUCCESS"
}
{
"success": false,
"errorCode": "",
"errorType": "JS_BRIDGE_ERROR",
"errorMessage": "",
"ret": "GP_EXCEPTION"
}
canIUse
Sample Request:
var params = {
api: 'GPMotion',
method: 'vibrate'
};
window.gpContainer.call(
"GPBase",
"canIUse",
params,
function(response) {
console.log('success:', response);
},
function(error) {
console.log('error:', error);
}
);
Sample Response: (error codes)
{
"success": true,
"ret": "GP_SUCCESS"
}
{
"success": false,
"errorCode": "",
"errorType": "JS_BRIDGE_ERROR",
"errorMessage": "",
"ret": "GP_EXCEPTION"
}
close
Sample Request:
window.gpContainer.call(
"GPMiniApp",
"close",
{},
function(response) {
console.log('success:', response);
},
function(error) {
console.log('error:', error);
}
);
Sample Response: (error codes)
{
"success": true,
"ret": "GP_SUCCESS"
}
{
"success": false,
"errorCode": "",
"errorType": "JS_BRIDGE_ERROR",
"errorMessage": "",
"ret": "GP_EXCEPTION"
}
pop
Sample Request:
window.gpContainer.call(
"GPNavigator",
"pop",
{},
function(response) {
console.log('success:', response);
},
function(error) {
console.log('error:', error);
}
);
Sample Response: (error codes)
{
"success": true,
"ret": "GP_SUCCESS"
}
{
"success": false,
"errorCode": "",
"errorType": "JS_BRIDGE_ERROR",
"errorMessage": "",
"ret": "GP_EXCEPTION"
}
push
Sample Request:
var params = {
url: 'xxxx'
};
window.gpContainer.call(
"GPNavigator",
"push",
params,
function(response) {
console.log('success:', response);
},
function(error) {
console.log('error:', error);
}
);
Sample Response: (error codes)
{
"success": true,
"ret": "GP_SUCCESS"
}
{
"success": false,
"errorCode": "",
"errorType": "JS_BRIDGE_ERROR",
"errorMessage": "",
"ret": "GP_EXCEPTION"
}
showLoadingBox
Sample Request:
window.gpContainer.call(
"GPUI",
"showLoadingBox",
{},
function(response) {
console.log('success:', response);
},
function(error) {
console.log('error:', error);
}
);
Sample Response: (error codes)
{
"success": true,
"ret": "GP_SUCCESS"
}
{
"success": false,
"errorCode": "",
"errorType": "JS_BRIDGE_ERROR",
"errorMessage": "",
"ret": "GP_EXCEPTION"
}
hideLoadingBox
Sample Request:
window.gpContainer.call(
"GPUI",
"hideLoadingBox",
{},
function(response) {
console.log('success:', response);
},
function(error) {
console.log('error:', error);
}
);
Sample Response: (error codes)
{
"success": true,
"ret": "GP_SUCCESS"
}
{
"success": false,
"errorCode": "",
"errorType": "JS_BRIDGE_ERROR",
"errorMessage": "",
"ret": "GP_EXCEPTION"
}
hideKeyboard
Sample Request:
window.gpContainer.call(
"GPUI",
"hideKeyboard",
{},
function(response) {
console.log('success:', response);
},
function(error) {
console.log('error:', error);
}
);
Sample Response: (error codes)
{
"success": true,
"ret": "GP_SUCCESS"
}
{
"success": false,
"errorCode": "",
"errorType": "JS_BRIDGE_ERROR",
"errorMessage": "",
"ret": "GP_EXCEPTION"
}
toast
Sample Request:
var params = {
// The toast message that you want to display.
message: 'Toast information',
// The duration for which the toast message is displayed.
duration: 5
};
window.gpContainer.call(
"GPUIToast",
"toast",
params,
function(response) {
console.log('success:', response);
},
function(error) {
console.log('error:', error);
}
);
Sample Response: (error codes)
{
"success": true,
"ret": "GP_SUCCESS"
}
{
"success": false,
"errorCode": "",
"errorType": "JS_BRIDGE_ERROR",
"errorMessage": "",
"ret": "GP_EXCEPTION"
}
alert
Sample Request:
var params = {
// The warning message that you want to display.
message: 'Hello World!',
// The OK button in the warning message.
okbutton: 'OK',
};
window.gpContainer.call(
"GPUIDialog",
"alert",
params,
function(response) {
console.log('success:', response);
},
function(error) {
console.log('error:', error);
}
);
Sample Response: (error codes)
{
"success": true,
"ret": "GP_SUCCESS"
}
{
"success": false,
"errorCode": "",
"errorType": "JS_BRIDGE_ERROR",
"errorMessage": "",
"ret": "GP_EXCEPTION"
}
confirm
Sample Request:
var params = {
// The confirmation message that you want to display.
message: 'Are you really really sure?',
// The OK button in the confirmation message.
okbutton: 'OK',
// The Cancel button in the confirmation message.
canclebutton: 'Cancel',
// The index of the confirmation message.
_index: 10086
};
window.gpContainer.call(
"GPUIDialog",
"confirm",
params,
function(response) {
console.log('success:', response);
},
function(error) {
console.log('error:', error);
}
);
document.addEventListener('gp.dialog', function(e) {
alert(JSON.stringify(e.param));
}, false);
Sample Response: (error codes)
{
"success": true,
"ret": "GP_SUCCESS"
}
{
"success": false,
"errorCode": "",
"errorType": "JS_BRIDGE_ERROR",
"errorMessage": "",
"ret": "GP_EXCEPTION"
}
enableAlertBeforeUnload
Sample Request:
var params = {
// The content in the dialog.
message: 'Confirm to leave?',
};
window.gpContainer.call(
"GPUI",
"enableAlertBeforeUnload",
params,
function(response) {
console.log('success:', response);
},
function(error) {
console.log('error:', error);
}
);
Sample Response: (error codes)
{
"success": true,
"ret": "GP_SUCCESS"
}
{
"success": false,
"errorCode": "",
"errorType": "JS_BRIDGE_ERROR",
"errorMessage": "",
"ret": "GP_EXCEPTION"
}
disableAlertBeforeUnload
Sample Request:
window.gpContainer.call(
"GPUI",
"disableAlertBeforeUnload",
{},
function(response) {
console.log('success:', response);
},
function(error) {
console.log('error:', error);
}
);
Sample Response: (error codes)
{
"success": true,
"ret": "GP_SUCCESS"
}
{
"success": false,
"errorCode": "",
"errorType": "JS_BRIDGE_ERROR",
"errorMessage": "",
"ret": "GP_EXCEPTION"
}
prompt
Sample Request:
var params = {
title: 'prompt message'
message: 'Enter xxx'
hint: 'Enter xxx'
okbutton: 'OK',
cancelbutton: 'Cancel'
};
window.gpContainer.call(
"GPUIDialog",
"prompt",
params,
function(response) {
console.log('success:', response);
},
function(error) {
console.log('error:', error);
}
);
Sample Response: (error codes)
{
"success": true,
"ret": "GP_SUCCESS"
}
{
"success": false,
"errorCode": "",
"errorType": "JS_BRIDGE_ERROR",
"errorMessage": "",
"ret": "GP_EXCEPTION"
}
showAuthGuide
Sample Request:
var params = {
permission: 'Address book'
cancelbutton: 'Cancel'
};
window.gpContainer.call(
"GPUIDialog",
"showAuthGuide",
params,
function(response) {
console.log('success:', response);
},
function(error) {
console.log('error:', error);
}
);
Sample Response: (error codes)
{
"success": true,
"ret": "GP_SUCCESS"
}
{
"success": false,
"errorCode": "",
"errorType": "JS_BRIDGE_ERROR",
"errorMessage": "",
"ret": "GP_EXCEPTION"
}
show
Sample Request:
var params = {
// The title of the action sheet.
title: 'Choose a button!',
// The index of the action sheet.
_index: 32768,
// The buttons that are displayed in the action sheet.
buttons: ['Button 1', 'Button 2', 'Button 3', 'Button 4', 'Button 5']
};
window.gpContainer.call(
"GPUIActionSheet",
"show",
params,
function(response) {
console.log('success:', response);
},
function(error) {
console.log('error:', error);
}
);
document.addEventListener('gp.actionsheet', function(e) {
alert(JSON.stringify(e.param));
}, false);
Sample Response: (error codes)
{
"success": true,
"ret": "GP_SUCCESS"
}
{
"success": false,
"errorCode": "",
"errorType": "JS_BRIDGE_ERROR",
"errorMessage": "",
"ret": "GP_EXCEPTION"
}
update
Sample Request:
var params = {
title: 'Home',
titleColor: '#FF00FF',
barStyle: 'float',
backgroundColor: '#00FFFF',
hideBackButton: 'false'
};
window.gpContainer.call(
"GPNavigationBar",
"update",
params,
function(response) {
console.log('success:', response);
},
function(error) {
console.log('error:', error);
}
);
Sample Response: (error codes)
{
"success": true,
"ret": "GP_SUCCESS"
}
{
"success": false,
"errorCode": "",
"errorType": "JS_BRIDGE_ERROR",
"errorMessage": "",
"ret": "GP_EXCEPTION"
}
getHeight
Sample Request:
window.gpContainer.call(
"GPNavigationBar",
"getHeight",
{},
function(response) {
console.log('success:', response);
},
function(error) {
console.log('error:', error);
}
);
Sample Response: (error codes)
{
"success": true,
"ret": "GP_SUCCESS"
}
{
"success": false,
"errorCode": "",
"errorType": "JS_BRIDGE_ERROR",
"errorMessage": "",
"ret": "GP_EXCEPTION"
}
saveImage
Sample Request:
var params = {
// The URL of the image to be saved.
url: 'https://gw.xxx.com/xxx/xxx.png',
};
window.gpContainer.call(
"GPImage",
"saveImage",
params,
function(response) {
console.log('success:', response);
},
function(error) {
console.log('error:', error);
}
);
Sample Response: (error codes)
{
"success": true,
"ret": "GP_SUCCESS"
}
{
"success": false,
"errorCode": "",
"errorType": "JS_BRIDGE_ERROR",
"errorMessage": "",
"ret": "GP_EXCEPTION"
}
chooseVideo
Sample Request:
var params = {
mode: 'both'
};
window.gpContainer.call(
"GPVideo",
"chooseVideo",
params,
function(response) {
console.log('success:', response);
},
function(error) {
console.log('error:', error);
}
);
document.addEventListener('GPVideo.Event.chooseVideoSuccess', function (e) {
alert('event chooseVideoSuccess: ' + JSON.stringify(e.param));
});
document.addEventListener('GPVideo.Event.chooseVideoFailed', function (e) {
alert('event chooseVideoSuccess: ' + JSON.stringify(e.param));
});
Sample Response: (error codes)
{
"success": true,
"ret": "GP_SUCCESS"
}
{
"success": false,
"errorCode": "",
"errorType": "JS_BRIDGE_ERROR",
"errorMessage": "",
"ret": "GP_EXCEPTION"
}
saveVideoToPhotosAlbum
Sample Request:
var params = {
url: 'http://xxxx'
};
window.gpContainer.call(
"GPVideo",
"saveVideoToPhotosAlbum",
params,
function(response) {
console.log('success:', response);
},
function(error) {
console.log('error:', error);
}
);
document.addEventListener('GPVideo.Event.saveVideoSuccess', function (e) {
alert('event saveVideoSuccess: ' + JSON.stringify(e.param));
});
document.addEventListener('GPVideo.Event.saveVideoFailed', function (e) {
alert('event saveVideoFailed: ' + JSON.stringify(e.param));
});
Sample Response: (error codes)
{
"success": true,
"ret": "GP_SUCCESS"
}
{
"success": false,
"errorCode": "",
"errorType": "JS_BRIDGE_ERROR",
"errorMessage": "",
"ret": "GP_EXCEPTION"
}
playSystemSound
Sample Request:
var params = {
// The ID of the system sound that you want to play.
sound: 1000
// The number of times that you want the sound to be played consecutively.
count: 3
};
window.gpContainer.call(
"GPAudio",
"playSystemSound",
params,
function(response) {
console.log('success:', response);
},
function(error) {
console.log('error:', error);
}
);
Sample Response: (error codes)
{
"success": true,
"ret": "GP_SUCCESS"
}
{
"success": false,
"errorCode": "",
"errorType": "JS_BRIDGE_ERROR",
"errorMessage": "",
"ret": "GP_EXCEPTION"
}
[Sound Table]
takePhoto
Sample Request:
var photoLocalPath; // The path to save the local file.
var params = {
mode: 'both',
};
window.gpContainer.call(
"GPCamera",
"takePhoto",
params,
function(response) {
var uploadParams = {
// The path in which the photo you want to upload is saved.
path: e.localPath
};
// Implement the transmission of file to the backend service for file storage.
...
...
console.log('success:', response);
},
function(error) {
console.log('error:', error);
}
);
Sample Response: (error codes)
{
"success": true,
"ret": "GP_SUCCESS"
}
{
"success": false,
"errorCode": "",
"errorType": "JS_BRIDGE_ERROR",
"errorMessage": "",
"ret": "GP_EXCEPTION"
}
[need to double check]
setItem
Sample Request:
var params = {
key: 'key',
value: 'value'
};
window.gpContainer.call(
"GPStorage",
"setItem",
params,
function(response) {
console.log('success:', response);
},
function(error) {
console.log('error:', error);
}
);
Sample Response: (error codes)
{
"success": true,
"ret": "GP_SUCCESS"
}
{
"success": false,
"errorCode": "",
"errorType": "JS_BRIDGE_ERROR",
"errorMessage": "",
"ret": "GP_EXCEPTION"
}
getItem
Sample Request:
var params = {
key: 'key'
};
window.gpContainer.call(
"GPStorage",
"getItem",
params,
function(response) {
console.log('success:', response);
},
function(error) {
console.log('error:', error);
}
);
Sample Response: (error codes)
{
"success": true,
"ret": "GP_SUCCESS"
}
{
"success": false,
"errorCode": "",
"errorType": "JS_BRIDGE_ERROR",
"errorMessage": "",
"ret": "GP_EXCEPTION"
}
removeItem
Sample Request:
var params = {
key: 'key'
};
window.gpContainer.call(
"GPStorage",
"removeItem",
params,
function(response) {
console.log('success:', response);
},
function(error) {
console.log('error:', error);
}
);
Sample Response: (error codes)
{
"success": true,
"ret": "GP_SUCCESS"
}
{
"success": false,
"errorCode": "",
"errorType": "JS_BRIDGE_ERROR",
"errorMessage": "",
"ret": "GP_EXCEPTION"
}
clearStorage
Sample Request:
window.gpContainer.call(
"GPStorage",
"clearStorage",
{},
function(response) {
console.log('success:', response);
},
function(error) {
console.log('error:', error);
}
);
Sample Response: (error codes)
{
"success": true,
"ret": "GP_SUCCESS"
}
{
"success": false,
"errorCode": "",
"errorType": "JS_BRIDGE_ERROR",
"errorMessage": "",
"ret": "GP_EXCEPTION"
}
clearStorageSync
Sample Request:
window.gpContainer.call(
"GPStorage",
"clearStorageSync",
{},
function(response) {
console.log('success:', response);
},
function(error) {
console.log('error:', error);
}
);
Sample Response: (error codes)
{
"success": true,
"ret": "GP_SUCCESS"
}
{
"success": false,
"errorCode": "",
"errorType": "JS_BRIDGE_ERROR",
"errorMessage": "",
"ret": "GP_EXCEPTION"
}
write
Sample Request:
var params = {
mode: 'overwrite',
data: 'Hello World!!!\n',
fileName: 'testFile.txt',
share: 'false'
};
window.gpContainer.call(
"GPFile",
"write",
params,
function(response) {
console.log('success:', response);
},
function(error) {
console.log('error:', error);
}
);
Sample Response: (error codes)
{
"success": true,
"ret": "GP_SUCCESS"
}
{
"success": false,
"errorCode": "",
"errorType": "JS_BRIDGE_ERROR",
"errorMessage": "",
"ret": "GP_EXCEPTION"
}
read
Sample Request:
var params = {
fileName: 'testFile.txt',
share: 'false'
};
window.gpContainer.call(
"GPFile",
"read",
params,
function(response) {
console.log('success:', response);
},
function(error) {
console.log('error:', error);
}
);
Sample Response: (error codes)
{
"success": true,
"ret": "GP_SUCCESS"
}
{
"success": false,
"errorCode": "",
"errorType": "JS_BRIDGE_ERROR",
"errorMessage": "",
"ret": "GP_EXCEPTION"
}
getFileInfo
Sample Request:
var params = {
filePath: '/storage/emulated/0/Android/data/xxx/testFile.txt',
};
window.gpContainer.call(
"GPFile",
"getFileInfo",
params,
function(response) {
console.log('success:', response);
},
function(error) {
console.log('error:', error);
}
);
Sample Response: (error codes)
{
"success": true,
"ret": "GP_SUCCESS"
}
{
"success": false,
"errorCode": "",
"errorType": "JS_BRIDGE_ERROR",
"errorMessage": "",
"ret": "GP_EXCEPTION"
}
downloadFile
Sample Request:
var params = {
url: 'http://xxxx',
name: 'test.mp4'
};
window.gpContainer.call(
"GPFile",
"downloadFile",
params,
function(response) {
console.log('success:', response);
},
function(error) {
console.log('error:', error);
}
);
document.addEventListener('GPFile.Event.downloadFileSuccess', function (e) {
alert('event downloadFileSuccess: ' + JSON.stringify(e.param));
});
document.addEventListener('GPFile.Event.downloadFileFailed', function (e) {
alert('event downloadFileFailed: ' + JSON.stringify(e.param));
});
Sample Response: (error codes)
{
"success": true,
"ret": "GP_SUCCESS"
}
{
"success": false,
"errorCode": "",
"errorType": "JS_BRIDGE_ERROR",
"errorMessage": "",
"ret": "GP_EXCEPTION"
}
uploadFile
Sample Request:
var params = {
url: 'http://xxxx',
filePath: '/storage/test.txt',
timeout: 8000,
headers: {
xxx: 'xxx'
}
};
window.gpContainer.call(
"GPFile",
"uploadFile",
params,
function(response) {
console.log('success:', response);
},
function(error) {
console.log('error:', error);
}
);
document.addEventListener('GPFile.Event.uploadFileSuccess', function (e) {
alert('event uploadFileSuccess: ' + JSON.stringify(e.param));
});
document.addEventListener('GPFile.Event.uploadFileFailed', function (e) {
alert('event uploadFileFailed: ' + JSON.stringify(e.param));
});
Sample Response: (error codes)
{
"success": true,
"ret": "GP_SUCCESS"
}
{
"success": false,
"errorCode": "",
"errorType": "JS_BRIDGE_ERROR",
"errorMessage": "",
"ret": "GP_EXCEPTION"
}
searchLocation
Sample Request:
var params = {
// The address that you want to search for.
addrs: ' No.960 xxxx West Road'
};
window.gpContainer.call(
"GPLocation",
"searchLocation",
params,
function(response) {
console.log('success:', response);
},
function(error) {
console.log('error:', error);
}
);
Sample Response: (error codes)
{
"success": true,
"ret": "GP_SUCCESS"
}
{
"success": false,
"errorCode": "",
"errorType": "JS_BRIDGE_ERROR",
"errorMessage": "",
"ret": "GP_EXCEPTION"
}
readCookie
Sample Request:
var params = {
// The URL from which you want to read cookies.
url: 'http://xxx.com'
};
window.gpContainer.call(
"GPCookie",
"read",
params,
function(response) {
console.log('success:', response);
},
function(error) {
console.log('error:', error);
}
);
Sample Response: (error codes)
{
"success": true,
"ret": "GP_SUCCESS"
}
{
"success": false,
"errorCode": "",
"errorType": "JS_BRIDGE_ERROR",
"errorMessage": "",
"ret": "GP_EXCEPTION"
}
writeCookie
Sample Request:
var params = {
// The cookie that you want to write. The cookie name is cookieKey and the value is cookieValue in the following sample code.
cookieKey: 'cookieValue',
domain: 'h5.m.taobao.com',
};
window.gpContainer.call(
"GPCookie",
"write",
params,
function(response) {
console.log('success:', response);
},
function(error) {
console.log('error:', error);
}
);
Sample Response: (error codes)
{
"success": true,
"ret": "GP_SUCCESS"
}
{
"success": false,
"errorCode": "",
"errorType": "JS_BRIDGE_ERROR",
"errorMessage": "",
"ret": "GP_EXCEPTION"
}
getSystemInfo
Sample Request:
window.gpContainer.call(
"GPSystem",
"getSystemInfo",
{},
function(response) {
console.log('success:', response);
},
function(error) {
console.log('error:', error);
}
);
Sample Response: (error codes)
{
"success": true,
"ret": "GP_SUCCESS"
}
{
"success": false,
"errorCode": "",
"errorType": "JS_BRIDGE_ERROR",
"errorMessage": "",
"ret": "GP_EXCEPTION"
}
getSystemInfoSync
Sample Request:
window.gpContainer.call(
"GPSystem",
"getSystemInfoSync",
{},
function(response) {
console.log('success:', response);
},
function(error) {
console.log('error:', error);
}
);
Sample Response: (error codes)
{
"success": true,
"ret": "GP_SUCCESS"
}
{
"success": false,
"errorCode": "",
"errorType": "JS_BRIDGE_ERROR",
"errorMessage": "",
"ret": "GP_EXCEPTION"
}
isSimulator
Sample Request:
window.gpContainer.call(
"GPNativeDetector",
"isSimulator",
{},
function(response) {
console.log('success:', response);
},
function(error) {
console.log('error:', error);
}
);
Sample Response: (error codes)
{
"success": true,
"ret": "GP_SUCCESS"
}
{
"success": false,
"errorCode": "",
"errorType": "JS_BRIDGE_ERROR",
"errorMessage": "",
"ret": "GP_EXCEPTION"
}
getCurrentUsage
Sample Request:
window.gpContainer.call(
"GPNativeDetector",
"getCurrentUsage",
{},
function(response) {
console.log('success:', response);
},
function(error) {
console.log('error:', error);
}
);
Sample Response: (error codes)
{
"success": true,
"ret": "GP_SUCCESS"
}
{
"success": false,
"errorCode": "",
"errorType": "JS_BRIDGE_ERROR",
"errorMessage": "",
"ret": "GP_EXCEPTION"
}
getDeviceYear
Sample Request:
window.gpContainer.call(
"GPNativeDetector",
"getDeviceYear",
{},
function(response) {
console.log('success:', response);
},
function(error) {
console.log('error:', error);
}
);
Sample Response: (error codes)
{
"success": true,
"ret": "GP_SUCCESS"
}
{
"success": false,
"errorCode": "",
"errorType": "JS_BRIDGE_ERROR",
"errorMessage": "",
"ret": "GP_EXCEPTION"
}
getModelInfo
Sample Request:
window.gpContainer.call(
"GPNativeDetector",
"getModelInfo",
{},
function(response) {
console.log('success:', response);
},
function(error) {
console.log('error:', error);
}
);
Sample Response: (error codes)
{
"success": true,
"ret": "GP_SUCCESS"
}
{
"success": false,
"errorCode": "",
"errorType": "JS_BRIDGE_ERROR",
"errorMessage": "",
"ret": "GP_EXCEPTION"
}
getSafeAreaInsets
Sample Request:
window.gpContainer.call(
"GPNativeDetector",
"getSafeAreaInsets",
{},
function(response) {
console.log('success:', response);
},
function(error) {
console.log('error:', error);
}
);
Sample Response: (error codes)
{
"success": true,
"ret": "GP_SUCCESS"
}
{
"success": false,
"errorCode": "",
"errorType": "JS_BRIDGE_ERROR",
"errorMessage": "",
"ret": "GP_EXCEPTION"
}
getNetworkType
Sample Request:
window.gpContainer.call(
"GPNetwork",
"getNetworkType",
{},
function(response) {
console.log('success:', response);
},
function(error) {
console.log('error:', error);
}
);
Sample Response: (error codes)
{
"success": true,
"ret": "GP_SUCCESS"
}
{
"success": false,
"errorCode": "",
"errorType": "JS_BRIDGE_ERROR",
"errorMessage": "",
"ret": "GP_EXCEPTION"
}
getOrientation
Sample Request:
window.gpContainer.call(
"GPScreen",
"getOrientation",
{},
function(response) {
console.log('success:', response);
},
function(error) {
console.log('error:', error);
}
);
Sample Response: (error codes)
{
"success": true,
"ret": "GP_SUCCESS"
}
{
"success": false,
"errorCode": "",
"errorType": "JS_BRIDGE_ERROR",
"errorMessage": "",
"ret": "GP_EXCEPTION"
}
setOrientation
Sample Request:
var params = {
orientation: 'landscape'
};
window.gpContainer.call(
"GPScreen",
"setOrientation",
params,
function(response) {
console.log('success:', response);
},
function(error) {
console.log('error:', error);
}
);
Sample Response: (error codes)
{
"success": true,
"ret": "GP_SUCCESS"
}
{
"success": false,
"errorCode": "",
"errorType": "JS_BRIDGE_ERROR",
"errorMessage": "",
"ret": "GP_EXCEPTION"
}
setScreenBrightness
Sample Request:
var params = {
brightness: '100'
};
window.gpContainer.call(
"GPScreen",
"setScreenBrightness",
params,
function(response) {
console.log('success:', response);
},
function(error) {
console.log('error:', error);
}
);
Sample Response: (error codes)
{
"success": true,
"ret": "GP_SUCCESS"
}
{
"success": false,
"errorCode": "",
"errorType": "JS_BRIDGE_ERROR",
"errorMessage": "",
"ret": "GP_EXCEPTION"
}
getScreenBrightness
Sample Request:
window.gpContainer.call(
"GPScreen",
"getScreenBrightness",
{},
function(response) {
console.log('success:', response);
},
function(error) {
console.log('error:', error);
}
);
Sample Response: (error codes)
{
"success": true,
"ret": "GP_SUCCESS"
}
{
"success": false,
"errorCode": "",
"errorType": "JS_BRIDGE_ERROR",
"errorMessage": "",
"ret": "GP_EXCEPTION"
}
capture
Sample Request:
var params = {
// Specify whether to save the screenshot as an image file in the album.
inAlbum: 'true'
};
window.gpContainer.call(
"GPScreenCapture",
"capture",
params,
function(response) {
console.log('success:', response);
},
function(error) {
console.log('error:', error);
}
);
Sample Response: (error codes)
{
"success": true,
"ret": "GP_SUCCESS"
}
{
"success": false,
"errorCode": "",
"errorType": "JS_BRIDGE_ERROR",
"errorMessage": "",
"ret": "GP_EXCEPTION"
}
listenBlow
Sample Request:
window.gpContainer.call(
"GPMotion",
"listenBlow",
{},
function(response) {
console.log('success:', response);
},
function(error) {
console.log('error:', error);
}
);
document.addEventListener('motion.blow', function(e) {
alert('A blow gesture is detected.');
}, false);
Sample Response: (error codes)
{
"success": true,
"ret": "GP_SUCCESS"
}
{
"success": false,
"errorCode": "",
"errorType": "JS_BRIDGE_ERROR",
"errorMessage": "",
"ret": "GP_EXCEPTION"
}
stopListenBlow
Sample Request:
window.gpContainer.call(
"GPMotion",
"stopListenBlow",
{},
function(response) {
console.log('success:', response);
},
function(error) {
console.log('error:', error);
}
);
Sample Response: (error codes)
{
"success": true,
"ret": "GP_SUCCESS"
}
{
"success": false,
"errorCode": "",
"errorType": "JS_BRIDGE_ERROR",
"errorMessage": "",
"ret": "GP_EXCEPTION"
}
listenGyro
Sample Request:
var params = {
// Enable or disable monitoring of the gyroscope.
on: true,
// The interval between gyroscope events.
frequency: 100
};
window.gpContainer.call(
"GPMotion",
"listenGyro",
params,
function(response) {
console.log('success:', response);
},
function(error) {
console.log('error:', error);
}
);
document.addEventListener('motion.gyro', function(e) {
alert ('A change in the phone orientation is detected.');
}, false);
Sample Response: (error codes)
{
"success": true,
"ret": "GP_SUCCESS"
}
{
"success": false,
"errorCode": "",
"errorType": "JS_BRIDGE_ERROR",
"errorMessage": "",
"ret": "GP_EXCEPTION"
}
listeningShake
Sample Request:
var params = {
// Enable or disable shake gesture monitoring.
on: true
};
window.gpContainer.call(
"GPMotion",
"listeningShake",
params,
function(response) {
console.log('success:', response);
},
function(error) {
console.log('error:', error);
}
);
document.addEventListener('motion.shake', function(e) {
alert ('A shake gesture is detected.');
}, false);
Sample Response: (error codes)
{
"success": true,
"ret": "GP_SUCCESS"
}
{
"success": false,
"errorCode": "",
"errorType": "JS_BRIDGE_ERROR",
"errorMessage": "",
"ret": "GP_EXCEPTION"
}
vibrate
Sample Request:
var params = {
// The vibration duration.
duration: 7000
};
window.gpContainer.call(
"GPMotion",
"vibrate",
{},
function(response) {
console.log('success:', response);
},
function(error) {
console.log('error:', error);
}
);
Sample Response: (error codes)
{
"success": true,
"ret": "GP_SUCCESS"
}
{
"success": false,
"errorCode": "",
"errorType": "JS_BRIDGE_ERROR",
"errorMessage": "",
"ret": "GP_EXCEPTION"
}
startAccelerometer
Sample Request:
var params = {
interval: 'normal'
};
window.gpContainer.call(
"GPMotion",
"startAccelerometer",
params,
function(response) {
console.log('success:', response);
},
function(error) {
console.log('error:', error);
}
);
document.addEventListener('GPMotion.Event.accelerometer', function (e) {
alert('event accelerometer: ' + JSON.stringify(e.param));
});
Sample Response: (error codes)
{
"success": true,
"ret": "GP_SUCCESS"
}
{
"success": false,
"errorCode": "",
"errorType": "JS_BRIDGE_ERROR",
"errorMessage": "",
"ret": "GP_EXCEPTION"
}
stopAccelerometer
Sample Request:
window.gpContainer.call(
"G{Motion",
"stopAccelerometer",
{},
function(response) {
console.log('success:', response);
},
function(error) {
console.log('error:', error);
}
);
Sample Response: (error codes)
{
"success": true,
"ret": "GP_SUCCESS"
}
{
"success": false,
"errorCode": "",
"errorType": "JS_BRIDGE_ERROR",
"errorMessage": "",
"ret": "GP_EXCEPTION"
}
StartCompass
Sample Request:
var params = {
/**
interval is either "game", "ui", or "normal". "normal" is default
"game" : 20ms
"ui": 60ms
"normal": 200ms
*/
interval: 'normal'
};
window.gpContainer.call(
"GPMotion",
"startCompass",
params,
function(response) {
console.log('success:', response);
},
function(error) {
console.log('error:', error);
}
);
// Listen to Compass result
document.addEventListener('GPMotion.Event.compass', (e: GPMotionCompassData) => {
console.log('Received gpAsyncCallback event:', JSON.stringify(e));
});
Sample Response: (error codes)
{
"success": true,
"ret": "GP_SUCCESS",
"msg": "COMPASS_STARTED"
}
{
direction: double, // The value due north between [0,360)
timestamp: int64
}
{
"success": false,
"errorCode": "",
"errorType": "JS_BRIDGE_ERROR",
"errorMessage": "",
"ret": "GP_EXCEPTION"
}
StopCompass
Sample Request:
window.gpContainer.call(
"GPMotion",
"stopCompass",
{},
function(response) {
console.log('success:', response);
},
function(error) {
console.log('error:', error);
}
);
Sample Response: (error codes)
{
"success": true,
"ret": "GP_SUCCESS",
"msg": "COMPASS_STOPPED"
}
{
"success": false,
"errorCode": "",
"errorType": "JS_BRIDGE_ERROR",
"errorMessage": "",
"ret": "GP_EXCEPTION"
}
beep
Sample Request:
var params = {
// The number of consecutive beeps.
count: 3
};
window.gpContainer.call(
"GPNotification",
"beep",
params,
function(response) {
console.log('success:', response);
},
function(error) {
console.log('error:', error);
}
);
Sample Response: (error codes)
{
"success": true,
"ret": "GP_SUCCESS"
}
{
"success": false,
"errorCode": "",
"errorType": "JS_BRIDGE_ERROR",
"errorMessage": "",
"ret": "GP_EXCEPTION"
}
dial
Sample Request:
var params = {
phone: '1320000000',
};
window.gpContainer.call(
"GPCall",
"dial",
params,
function(response) {
console.log('success:', response);
},
function(error) {
console.log('error:', error);
}
);
Sample Response: (error codes)
{
"success": true,
"ret": "GP_SUCCESS"
}
{
"success": false,
"errorCode": "",
"errorType": "JS_BRIDGE_ERROR",
"errorMessage": "",
"ret": "GP_EXCEPTION"
}
call
Sample Request:
var params = {
phone: '1320000000',
};
window.gpContainer.call(
"GPCall",
"call",
params,
function(response) {
console.log('success:', response);
},
function(error) {
console.log('error:', error);
}
);
Sample Response: (error codes)
{
"success": true,
"ret": "GP_SUCCESS"
}
{
"success": false,
"errorCode": "",
"errorType": "JS_BRIDGE_ERROR",
"errorMessage": "",
"ret": "GP_EXCEPTION"
}
appState
Sample Request:
window.gpContainer.call(
"GPApplication",
"appState",
{},
function(response) {
console.log('success:', response);
},
function(error) {
console.log('error:', error);
}
);
Sample Response: (error codes)
{
"success": true,
"ret": "GP_SUCCESS"
}
{
"success": false,
"errorCode": "",
"errorType": "JS_BRIDGE_ERROR",
"errorMessage": "",
"ret": "GP_EXCEPTION"
}
getNotificationSettings
Sample Request:
window.gpContainer.call(
"GPApplication",
"getNotificationSettings",
{},
function(response) {
console.log('success:', response);
},
function(error) {
console.log('error:', error);
}
);
Sample Response: (error codes)
{
"success": true,
"ret": "GP_SUCCESS"
}
{
"success": false,
"errorCode": "",
"errorType": "JS_BRIDGE_ERROR",
"errorMessage": "",
"ret": "GP_EXCEPTION"
}
openSettings
Sample Request:
window.gpContainer.call(
"GPApplication",
"openSettings",
{},
function(response) {
console.log('success:', response);
},
function(error) {
console.log('error:', error);
}
);
Sample Response: (error codes)
{
"success": true,
"ret": "GP_SUCCESS"
}
{
"success": false,
"errorCode": "",
"errorType": "JS_BRIDGE_ERROR",
"errorMessage": "",
"ret": "GP_EXCEPTION"
}
askAuth
Sample Request:
window.gpContainer.call(
"GPContacts",
"askAuth",
{},
function(response) {
console.log('success:', response);
},
function(error) {
console.log('error:', error);
}
);
Sample Response: (error codes)
{
"success": true,
"ret": "GP_SUCCESS"
}
{
"success": false,
"errorCode": "",
"errorType": "JS_BRIDGE_ERROR",
"errorMessage": "",
"ret": "GP_EXCEPTION"
}
authStatus
Sample Request:
window.gpContainer.call(
"GPContacts",
"authStatus",
{},
function(response) {
console.log('success:', response);
},
function(error) {
console.log('error:', error);
}
);
Sample Response: (error codes)
{
"success": true,
"ret": "GP_SUCCESS"
}
{
"success": false,
"errorCode": "",
"errorType": "JS_BRIDGE_ERROR",
"errorMessage": "",
"ret": "GP_EXCEPTION"
}
choose
Sample Request:
window.gpContainer.call(
"GPContacts",
"choose",
params,
function(response) {
console.log('success:', response);
},
function(error) {
console.log('error:', error);
}
);
Sample Response: (error codes)
{
"success": true,
"ret": "GP_SUCCESS"
}
{
"success": false,
"errorCode": "",
"errorType": "JS_BRIDGE_ERROR",
"errorMessage": "",
"ret": "GP_EXCEPTION"
}
find
Sample Request:
var params = {
// The contact filter.
filter: {
// Search for a contact with a specified name.
name: 'Jack',
// Search for a contact with a specified phone number.
phone: '123456'
};
window.gpContainer.call(
"GPContacts",
"find",
params,
function(response) {
console.log('success:', response);
},
function(error) {
console.log('error:', error);
}
);
Sample Response: (error codes)
{
"success": true,
"ret": "GP_SUCCESS"
}
{
"success": false,
"errorCode": "",
"errorType": "JS_BRIDGE_ERROR",
"errorMessage": "",
"ret": "GP_EXCEPTION"
}
addPhoneContact
Sample Request:
var params = {
lastName: 'xxx',
firstName: 'xxx',
middleName:'xxx',
nickName: 'xxx',
remark: 'xxx',
mobilePhoneNumber: '+86 12345',
hostNumber: '12345',
address: 'Beijing Chaoyang',
email: '[email protected]',
organization: 'xxx',
title: 'xxx',
photoPath: '/storage/emulated/0/DCIM/Camera/xxx.jpg
};
window.gpContainer.call(
"GPContacts",
"addPhoneContact",
params,
function(response) {
console.log('success:', response);
},
function(error) {
console.log('error:', error);
}
);
Sample Response: (error codes)
{
"success": true,
"ret": "GP_SUCCESS"
}
{
"success": false,
"errorCode": "",
"errorType": "JS_BRIDGE_ERROR",
"errorMessage": "",
"ret": "GP_EXCEPTION"
}
scan
Sample Request:
var params = {
openFlight: true,
title: 'XXX'
};
window.gpContainer.call(
"GPScan",
"scan",
params,
function(response) {
console.log('success:', response);
},
function(error) {
console.log('error:', error);
}
);
document.addEventListener('GPScan.Event.scanSuccess', function (e) {
alert('event scanSuccess: ' + JSON.stringify(e.param));
});
document.addEventListener('GPScan.Event.scanFailed', function (e) {
alert('event scanFailed: ' + JSON.stringify(e.param));
});
Sample Response: (error codes)
{
"success": true,
"ret": "GP_SUCCESS"
}
{
"success": false,
"errorCode": "",
"errorType": "JS_BRIDGE_ERROR",
"errorMessage": "",
"ret": "GP_EXCEPTION"
}
getBatteryInfo
Sample Request:
window.gpContainer.call(
"GPBattery",
"getBatteryInfo",
{},
function(response) {
console.log('success:', response);
},
function(error) {
console.log('error:', error);
}
);
Sample Response: (error codes)
{
"success": true,
"ret": "GP_SUCCESS"
}
{
"success": false,
"errorCode": "",
"errorType": "JS_BRIDGE_ERROR",
"errorMessage": "",
"ret": "GP_EXCEPTION"
}
getBatteryInfoSync
Sample Request:
window.gpContainer.call(
"GPBattery",
"getBatteryInfoSync",
{},
function(response) {
console.log('success:', response);
},
function(error) {
console.log('error:', error);
}
);
Sample Response: (error codes)
{
"success": true,
"ret": "GP_SUCCESS"
}
{
"success": false,
"errorCode": "",
"errorType": "JS_BRIDGE_ERROR",
"errorMessage": "",
"ret": "GP_EXCEPTION"
}
requestAuthorization
Sample Request:
window.gpContainer.call(
"GPBluetooth",
"requestAuthorization",
{},
function(response) {
console.log('success:', response);
},
function(error) {
console.log('error:', error);
}
);
Sample Response: (error codes)
{
"success": true,
"ret": "GP_SUCCESS"
}
{
"success": false,
"errorCode": "",
"errorType": "JS_BRIDGE_ERROR",
"errorMessage": "",
"ret": "GP_EXCEPTION"
}
scanBluetooth
Sample Request:
var params = {
text: "string"
};
window.gpContainer.call(
"GPBluetooth",
"scan",
params,
function(response) {
console.log('success:', response);
},
function(error) {
console.log('error:', error);
}
);
document.addEventListener('GP.Event.GPBluetooth.discoverDevice', function (e) {
alert('event discoverDevice: ' + JSON.stringify(e.param));
});
Sample Response: (error codes)
{
"success": true,
"ret": "GP_SUCCESS"
}
{
"success": false,
"errorCode": "",
"errorType": "JS_BRIDGE_ERROR",
"errorMessage": "",
"ret": "GP_EXCEPTION"
}
stopScan
Sample Request:
window.gpContainer.call(
"GPBluetooth",
"stopScan",
{},
function(response) {
console.log('success:', response);
},
function(error) {
console.log('error:', error);
}
);
Sample Response: (error codes)
{
"success": true,
"ret": "GP_SUCCESS"
}
{
"success": false,
"errorCode": "",
"errorType": "JS_BRIDGE_ERROR",
"errorMessage": "",
"ret": "GP_EXCEPTION"
}
connect
Sample Request:
var params = {
deviceId: '00:aa:bb:cc:dd'
};
window.gpContainer.call(
"GPBluetooth",
"connect",
params,
function(response) {
console.log('success:', response);
},
function(error) {
console.log('error:', error);
}
);
Sample Response: (error codes)
{
"success": true,
"ret": "GP_SUCCESS"
}
{
"success": false,
"errorCode": "",
"errorType": "JS_BRIDGE_ERROR",
"errorMessage": "",
"ret": "GP_EXCEPTION"
}
disconnect
Sample Request:
window.gpContainer.call(
"GPBluetooth",
"disconnect",
{},
function(response) {
console.log('success:', response);
},
function(error) {
console.log('error:', error);
}
);
document.addEventListener('GP.Event.GPBluetooth.GATTServerDisconnected', function (e) {
alert('event GATTServerDisconnected: ' + JSON.stringify(e.param));
});
Sample Response: (error codes)
{
"success": true,
"ret": "GP_SUCCESS"
}
{
"success": false,
"errorCode": "",
"errorType": "JS_BRIDGE_ERROR",
"errorMessage": "",
"ret": "GP_EXCEPTION"
}
getServices
Sample Request:
var params = {
deviceId: '00:aa:bb:cc:dd'
};
window.gpContainer.call(
"GPBluetooth",
"getServices",
params,
function(response) {
console.log('success:', response);
},
function(error) {
console.log('error:', error);
}
);
Sample Response: (error codes)
{
"success": true,
"ret": "GP_SUCCESS"
}
{
"success": false,
"errorCode": "",
"errorType": "JS_BRIDGE_ERROR",
"errorMessage": "",
"ret": "GP_EXCEPTION"
}
getCharacteristics
Sample Request:
var params = {
deviceId: '00:aa:bb:cc:dd',
serviceId: 'xxxx'
};
window.gpContainer.call(
"GPBluetooth",
"getCharacteristics",
params,
function(response) {
console.log('success:', response);
},
function(error) {
console.log('error:', error);
}
);
Sample Response: (error codes)
{
"success": true,
"ret": "GP_SUCCESS"
}
{
"success": false,
"errorCode": "",
"errorType": "JS_BRIDGE_ERROR",
"errorMessage": "",
"ret": "GP_EXCEPTION"
}
writeValue
Sample Request:
var params = {
deviceId: '00:aa:bb:cc:dd',
serviceId: 'xxxx',
characteristicId: 'xxx',
value: 'xxx'
};
window.gpContainer.call(
"GPBluetooth",
"writeValue",
params,
function(response) {
console.log('success:', response);
},
function(error) {
console.log('error:', error);
}
);
Sample Response: (error codes)
{
"success": true,
"ret": "GP_SUCCESS"
}
{
"success": false,
"errorCode": "",
"errorType": "JS_BRIDGE_ERROR",
"errorMessage": "",
"ret": "GP_EXCEPTION"
}
readValue
Sample Request:
var params = {
deviceId: '00:aa:bb:cc:dd',
serviceId: 'xxxx',
characteristicId: 'xxx',
};
window.gpContainer.call(
"GPBluetooth",
"readValue",
params,
function(response) {
console.log('success:', response);
},
function(error) {
console.log('error:', error);
}
);
Sample Response: (error codes)
{
"success": true,
"ret": "GP_SUCCESS"
}
{
"success": false,
"errorCode": "",
"errorType": "JS_BRIDGE_ERROR",
"errorMessage": "",
"ret": "GP_EXCEPTION"
}
startNotifications
Sample Request:
var params = {
deviceId: '00:aa:bb:cc:dd',
serviceId: 'xxxx',
characteristicId: 'xxx',
};
window.gpContainer.call(
"GPBluetooth",
"startNotifications",
params,
function(response) {
console.log('success:', response);
},
function(error) {
console.log('error:', error);
}
);
Sample Response: (error codes)
{
"success": true,
"ret": "GP_SUCCESS"
}
{
"success": false,
"errorCode": "",
"errorType": "JS_BRIDGE_ERROR",
"errorMessage": "",
"ret": "GP_EXCEPTION"
}
stopNotifications
Sample Request:
var params = {
deviceId: '00:aa:bb:cc:dd',
serviceId: 'xxxx',
characteristicId: 'xxx',
};
window.gpContainer.call(
"GPBluetooth",
"stopNotifications",
params,
function(response) {
console.log('success:', response);
},
function(error) {
console.log('error:', error);
}
);
Sample Response: (error codes)
{
"success": true,
"ret": "GP_SUCCESS"
}
{
"success": false,
"errorCode": "",
"errorType": "JS_BRIDGE_ERROR",
"errorMessage": "",
"ret": "GP_EXCEPTION"
}
postNotificationToNative
IOS event listeners
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(myEventListener) name:eventName object:nil]
- (void)myEventListener:(NSNotification *)notification {
// Specify to obtain the event parameters from notification.userInfo.
}
Android event listener
@import android.taobao.windvane.service;
@import android.taobao.windvane.standardmodal
// Implement a listener.
public class JsEventListener implements GPEventListener {
@Override
public GPEventResult onEvent(int id, GPEventContext ctx, Object... obj) {
// All events are sent to the listener. GPEventId.H5TONATIVE_EVENT indicates the events sent by HTML5 apps or MiniApps.
if (id == GPEventId.H5TONATIVE_EVENT) {
if (obj[0] instanceof String) {
String params = (String)obj[0];
// params is a JSON string that contains two parameters – event and param. You need to deserialize the string.
}
}
return null;
}
}
// Register a listener.
GPEventService.getInstance().addEventListener(new JsEventListener());
Sample Request:
var params = {
event: 'eventName',
param: {
// The data of the event to be sent.
}
};
window.gpContainer.call(
"GPStandardEventCenter",
"postNotificationToNative",
params,
function(response) {
console.log('success:', response);
},
function(error) {
console.log('error:', error);
}
);
Sample Response: (error codes)
{
"success": true,
"ret": "GP_SUCCESS"
}
{
"success": false,
"errorCode": "",
"errorType": "JS_BRIDGE_ERROR",
"errorMessage": "",
"ret": "GP_EXCEPTION"
}
Background
Sample Request:
document.addEventListener('GP.Event.APP.Background', function(e) {
// For some models, an alert is triggered when the app exits, which will cause a system bug.
console.log('Event Background');
}, false);
Sample Response: (error codes)
{
"success": true,
"ret": "GP_SUCCESS"
}
{
"success": false,
"errorCode": "",
"errorType": "JS_BRIDGE_ERROR",
"errorMessage": "",
"ret": "GP_EXCEPTION"
}
Active
Sample Request:
document.addEventListener('GP.Event.APP.Active', function(e) {
alert('Event Active');
}, false);
Sample Response: (error codes)
{
"success": true,
"ret": "GP_SUCCESS"
}
{
"success": false,
"errorCode": "",
"errorType": "JS_BRIDGE_ERROR",
"errorMessage": "",
"ret": "GP_EXCEPTION"
}
Pull Refresh
Sample Request:
//In the iOS system, WindVane enables the pull-to-refresh feature by default. To disable pull-to-refresh, add the following metadata to the <head> element of HTML:
<meta id="stopUsePullRefresh" value="true">
//You can specify whether to display the URL of the current page in the prompt section when a pull-to-refresh action is taken. To display the URL of the current page, add the following metadata to the <head> element of HTML:
<meta id="urlInLaw" value="true">
Sample Response: (error codes)
{
"success": true,
"ret": "GP_SUCCESS"
}
{
"success": false,
"errorCode": "",
"errorType": "JS_BRIDGE_ERROR",
"errorMessage": "",
"ret": "GP_EXCEPTION"
}
Infinite Scroll
//Loads more content when the user scrolls to the bottom of the page. To enable infinite scrolling, add the following metadata to the <head> element of HTML:
<meta id="infiniteScroll" value="true">
//In GoPay Container SDK of the iOS system, add the following metadata to the <head> element of HTML:
<meta id="urlInLaw" value="true">
Sample Request:
document.addEventListener('GP_INFINIT_SCROLL', function(e) {
var data = 'New document element for infinit scroll';
window.gpContainer.call('GPScrollWidget', 'hiddenInfinitScroll', {}, function(e) {
var newDiv = document.createElement('div');
newDiv.innerHTML = data;
document.body.appendChild(newDiv);
});
}, false);
Sample Response: (error codes)
{
"success": true,
"ret": "GP_SUCCESS"
}
{
"success": false,
"errorCode": "",
"errorType": "JS_BRIDGE_ERROR",
"errorMessage": "",
"ret": "GP_EXCEPTION"
}
Error Codes
Codes | Description |
---|---|
'GP_SUCCESS' | Indicates that the API call is successful. This value is used only in a success callback. |
'GP_CLOSED' | Indicates that the JSBridge feature is forcibly disabled. In most cases, this issue occurs because the URL of the page is not specified in the list of trusted domains or the JSBridge feature is not enabled for native apps. If this issue occurs, check the URL or contact HTML5 container-native developers to troubleshoot the issue. |
'GP_NO_HANDLER' | Indicates that the current client does not provide this API. Check whether the called JSBridge is correct and contact the provider of the native apps for JSBridge to troubleshoot the issue. |
'GP_PARAM_ERR' | Indicates that the input parameter is invalid. Make sure that the input parameter is valid. |
'GP_NO_PERMISSION' | Indicates that the current page does not have permissions to call this API. |
'GP_FAILED' | Indicates that the API call fails. Contact the provider of the native apps for JSBridge to troubleshoot the issue. |
'GP_EXCEPTION' | Indicates that an error occurs when the API is called. Contact the provider of the native apps for JSBridge to troubleshoot the issue. |
'GP_USER_DENIED' | Indicates that the API is not granted the permissions to perform the operation. For example, a client wants to call this API to access the album, but the client is not allowed to access the album. |
'GP_USER_CANCELLED' | Indicates that the user canceled the current API request. |
'GP_RET_PHOTO_CANCEL' | Indicates that the user cancels the request for taking photos by using the API provided by GPCamera. |
'GP_TIMEOUT' | Indicates that the call of JSBridge times out. |
'GP_RESULT_PARSE_ERROR' | Indicates that the format of the data passed by native apps to HTML5 is invalid. |
'GP_NOT_IN_WINDVANE' | Indicates that the current environment is not WindVane such as a browser, or that UserAgent of WindVane provided by the client is invalid. Alternatively, JavaScript of the page incorrectly modified an environment variable in the windvane.js file. For example, WindVane.isAvailable is set to false. |
'GP_NOT_SUPPORT_DEVICE' | Indicates that JSBridge is called on a device or in an environment that is not supported, such as a browser. Alternatively, a JavaScript action on the page incorrectly modified an environment variable in the windvane.js file. For example, WindVane.isAvailable is set to false. |
'GP_NO_HANDLER_ON_WP' | Indicates that JSBridge is called on a Windows device or in an environment that is not supported, such as a browser. |
'GP_ERR::PARAM_PARSE_ERROR' | Indicates that the format of the data passed by native apps to HTML5 is invalid. |