JSAPI reference

Basic

API Name

Function Description

my.canIUse

Judge whether the current Mini Program API, incoming parameter or return value, component, attribute, etc. are supported in the current version.

my.SDKVersion

Get the SDK version.

my.getAppIdSync

Obtain the Mini Program App ID synchronously.

my.getRunScene

Obtain the running version of the current Mini Program.

In-App Event

API Name

Function Description

my.offAppHide

Unlisten for the event that the mini program is switched to background from foreground.

my.offAppShow

Unlisten for the event that the mini program is switched to foreground from background.

my.onAppHide

Listen for the event that the mini program is switched to background from foreground.

my.onAppShow

Listen for the event that the mini program is switched to foreground from background.

my.offError

Unlisten for the event that JS errors occur in the mini program.

my.onError

Listen for the event that errors occur in the mini program.

my.offUnhandledRejection

Unlisten for the unhandledrejection event.

my.onUnhandledRejection

Listen for the unhandledrejection event.

UI

API Name

Function Description

my.hideBackHome

Hide back to home button.

my.showNavigationBarLoading

Show navigation bar loading.

my.hideNavigationBarLoading

Hide navigation bar loading.

my.setNavigationBar

Set the navigation bar text and style.

TabBar

API Name

Function Description

my.hideTabBar

Hide the tabBar.

my.setTabBarStyle

Set the style of tabBar.

Note: For the FAQs of tab bar, see TabBar FAQ.

Route

API Name

Function Description

my.switchTab

Jump to the specified tabBar page and close all other pages that are not tabBar.

my.navigateTo

Maintain the current page and jump to the specified page within the application. Use my.navigateBack to return to the original page.

my.navigateBack

Close the current page and return to the previous one or more pages.

my.redirectTo

Close the current page and jump to the specified page within the application.

my.reLaunch

Close all current pages and jump to the specified page within the application.

Feedback

API Name

Function Description

my.alert

Alert box.

my.confirm

Confirm box.

my.prompt

Prompt box.

my.showLoading

Show the loading hint.

my.hideLoading

Hide the loading hint.

my.showToast

Show a weak hint, which disappears in the specified seconds.

my.hideToast

Hide the weak hint.

my.showActionSheet

Display an operation menu.

Pulldown

API Name

Function Description

my.startPullDownRefresh

Start the pull-to-refresh function.

onPullDownRefresh

On the Page, customize the onPullDownRefresh function to listen to the pull-to-refresh event of user.

my.stopPullDownRefresh

Stop the pull-to-refresh for the current page.

Contact

API Name

Function Description

my.choosePhoneContact

Choose contact from system contact.

Choose Data

API Name

Function Description

my.datePicker

Open a date selection list.

Animation

API Name

Function Description

my.createAnimation

Create an instance of animation.

Canvas

API Name

Function Description

my.createCanvasContext

Create the context of the canvas.

For more information about CanvasContext, see CanvasContext Overview.

Keyboard

API Name

Function Description

my.hideKeyboard

Hide keyboard.

Scroll

API Name

Function Description

my.pageScrollTo

Scroll to the destination location of the page.

SelectorQuery

API Name

Function Description

my.createSelectorQuery

Create an instance of SelectorQuery.

For more information about SelectorQuery, see SelectorQuery Overview.

Multiple Level Select

API Name

Function Description

my.multiLevelSelect

Multiple level selector, used for associated select with multiple levels.

Set Background

API Name

Function Description

my.setBackgroundColor

Set background color.

Set Page Pulldown

API Name

Function Description

my.setCanPullDown

Set whether page can support pulldown.

Media

Image

API Name

Function Description

my.chooseImage

Choose image from camera or album of cellphone.

my.previewImage

Preview image.

my.saveImage

Save the online images to cellphone album.

my.getImageInfo

Get the information of the image.

my.compressImage

Compress large images to fulfill the size restrictions from some mini programs.

Video

API Name

Function Description

my.chooseVideo

Shoot a video or choose a video from the album.

Lottie

API Name

Function Description

my.createLottieContext

Create and return a Lottie context object lottieContext.

Storage

API Name

Function Description

my.getStorage

Get cached data.

my.getStorageSync

Get cached data synchronously.

my.setStorage

Store the data in the specified key in the local cache, which overlaps the original data corresponding to the key.

my.setStorageSync

Store synchronously the data in the specified key in the local cache.

my.removeStorage

Remove cached data.

my.removeStorageSync

Remove cached data synchronously.

my.clearStorage

Clear local data cache.

my.clearStorageSync

Clear local data cache synchronously.

File

API Name

Function Description

my.saveFile

Save file to the device.

my.getFileInfo

Get the information of the file.

my.getSavedFileInfo

Get the information of the saved file.

my.getSavedFileList

Get the information of all the saved file.

my.removeSavedFile

Remove the saved file.

my.chooseFileFromDisk

Choose a file to upload.

my.openDocument

Enable users to preview a PDF file within the mini program.

Location

API Name

Function Description

my.getLocation

Get the current geographical location of the user.

my.openLocation

View the location on the built-in map.

my.chooseLocation

Open the built-in map to choose a location.

Map

API Name

Function Description

my.createMapContext

Create and return a map context object mapContext.

my.calculateRoute

Calculate the route.

Network

API Name

Function Description

my.request

Network request.

my.uploadFile

Upload the local resource to the developer server.

my.downloadFile

Download file resource to local location.

my.connectSocket

Create a WebSocket connection.

my.onSocketOpen

Listen to the event of enabling the WebSocket connection.

my.offSocketOpen

Unlisten to the event of enabling the WebSocket connection.

my.onSocketError

Listen to WebSocket error events.

my.offSocketError

Unlisten to WebSocket error events.

my.sendSocketMessage

Send data over WebSocket connection.

my.onSocketMessage

Listen to the event of receiving server messages by WebSocket.

my.offSocketMessage

Unlisten to the event of receiving server messages by WebSocket.

my.closeSocket

Close the WebSocket connection.

my.onSocketClose

Listen to the event of closing the WebSocket connection.

my.offSocketClose

Unlisten to the event of closing the WebSocket connection.

Device

System Information

API Name

Function Description

my.getSystemInfo

Get system information.

Network Status

API Name

Function Description

my.getNetworkType

Get the current network status.

Clipboard

API Name

Function Description

my.getClipboard

Get the clipboard data.

my.setClipboard

Set the clipboard data.

Watch Shake

API Name

Function Description

my.watchShake

The watchshake function.

Accelerometer

API Name

Function Description

my.onAccelerometerChange

Listen to the acceleration data event.

my.offAccelerometerChange

Unlisten to the acceleration data event.

Compass

API Name

Function Description

my.onCompassChange

Listen to the compass data change event.

my.offCompassChange

Unlisten to the compass data change event.

Vibrate

API Name

Function Description

my.vibrate

Invoke the vibrate ability of device.

Make Phone Call

API Name

Function Description

my.makePhoneCall

Make a phone call.

Get Server Time

API Name

Function Description

my.getServerTime

Get the server time.

Capture Screen

API Name

Function Description

my.onUserCaptureScreen

Listen to the capture screen event by users.

my.offUserCaptureScreen

Cancel the listen to the capture screen event by users.

Screen Brightness

API Name

Function Description

my.setKeepScreenOn

Set whether screen keeps awake.

my.getScreenBrightness

Get the screen brightness.

my.setScreenBrightness

Set the screen brightness.

Screen Orientation

API Name

Function Description

my.getScreenOrientation

Get screen orientation

my.setScreenOrientation

Set screen orientation

Setting

API Name

Function Description

my.openSetting

Open the mini program settings page.

my.getSetting

Obtain the user's current settings.

Add Phone Contact

API Name

Function Description

my.addPhoneContact

Add contact to phone contact.

Permission Guide

API Name

Function Description

my.showAuthGuide

Guide user to grant the authorization when the permission needed.

Scan

API Name

Function Description

my.scan

Call the scanning QR code function.

Memory Warning

API Name

Function Description

my.onMemoryWarning

Listen to the insufficient memory alarm event.

my.offMemoryWarning

Unlisten to the insufficient memory alarm event.

Battery Information

API Name

Function Description

my.getBatteryInfo

Obtain the battery level and the charging state of the current device asynchronously.

my.getBatteryInfoSync

Obtain the battery level and the charging state of the current device synchronously.

Bluetooth

Reference

Reference

Description

Bluetooth API Overview

Provide the system requirement and the process flow on how the Bluetooth APIs work.

Bluetooth API Error Codes

List the normal error code and relative solutions.

Bluetooth API FAQ

FAQs about using Bluetooth API.

BLE

API Name

Function Description

my.connectBLEDevice

Connect to low energy Bluetooth devices.

my.disconnectBLEDevice

Disconnect to low energy Bluetooth devices.

my.getBLEDeviceCharacteristics

Get the characteristics of low energy Bluetooth devices.

my.getBLEDeviceServices

Get all the low energy Bluetooth devices that are discovered, including the connected devices.

my.notifyBLECharacteristicValueChange

Enable the function to notify changes to the characteristic value.

my.offBLECharacteristicValueChange

Disable the function to notify changes to the characteristic value.

my.offBLEConnectionStateChanged

Disable the the event listener for the connection status.

my.onBLECharacteristicValueChange

Enable the event listener for changes to the characteristic value.

my.onBLEConnectionStateChanged

Enable the event listener for changes to the connection status, such as device lost and device disconnected.

my.readBLECharacteristicValue

Read the characteristic value.

my.writeBLECharacteristicValue

Write data to the characteristic value.

Bluetooth

API Name

Function Description

my.closeBluetoothAdapter

Close the Bluetooth module in the mini program.

my.openBluetoothAdapter

Initialize the Bluetooth module in the mini program.

my.getBluetoothAdapterState

Check the Bluetooth adapter status in the mini program.

my.startBluetoothDevicesDiscovery

Start discovering Bluetooth devices.

my.stopBluetoothDevicesDiscovery

Stop discovering Bluetooth devices.

my.getBluetoothDevices

Get all the Bluetooth devices that are discovered, including those that are connected to the current device.

my.getConnectedBluetoothDevices

Get the Bluetooth devices that are connected.

my.onBluetoothDeviceFound

Use this API when a new Bluetooth device is found.

my.offBluetoothDeviceFound

Remove the Bluetooth devices that are found.

my.onBluetoothAdapterStateChange

Monitor the Bluetooth adapter state changes.

my.offBluetoothAdapterStateChange

Remove the Bluetooth adapter with a state change.

Biometric authentication

API name

Description

my.checkLocalBioAuthSupported

Check the availability of biometric authentication on the user's device.

my.startLocalBioAuth

Initiate a biometric authentication process on the user's device.

Sharing

API Name

Function Description

my.showSharePanel

Trigger the sharing.

Update

API Name

Function Description

my.getUpdateManager

Create an UpdateManager object.

web-view

API Name

Function Description

my.createWebViewContext

By creating webViewContext, mini program can send message to web-view. This API will create a webViewContext instance.

Alipay Connect

API Name

Function Description

my.getSiteInfo

Get the site information assigned by Alipay Connect.

Open Capabilities

API Name

Function Description

my.navigateToMiniProgram

Jump to another mini program.

my.navigateBackMiniProgram

Return to the previous mini program, only when another mini program jumps to the current mini program.

my.getAuthCode

Get auth code.

my.getOpenUserInfo

Get basic information about user.

my.tradePay

Start to pay.

my.signContract

Sign the withholding contract.