Device
The Device API exposes hardware and system information.
Try it online
Click a button to show JSON or a message here
Import
import woo from 'mini-sdk'
// 或
import { device } from 'mini-sdk'Device information
getSystemInfo
Returns system information.
const info = await woo.getSystemInfo()Return value GetSystemInfoResult:
| Field | Type | Description |
|---|---|---|
platform | string | OS (ios / android / simulator) |
system | string | OS version |
brand | string | Device brand |
model | string | Device model |
screenWidth | number | Screen width (px) |
screenHeight | number | Screen height (px) |
windowWidth | number | Usable window width |
windowHeight | number | Usable window height |
statusBarHeight | number | Status bar height |
language | string | System language |
version | string | Host app version |
SDKVersion | string | SDK version |
getDeviceId
Returns a stable device identifier.
const { deviceId } = await woo.getDeviceId()getDeviceInfo
Returns basic device information.
const info = await woo.getDeviceInfo()getAppInfo
Returns the current mini program’s app information.
const info = await woo.getAppInfo()
// { appId, appName, env: 'simulator' | 'production', ... }Location
getLocation
Gets the current geographic location.
const location = await woo.getLocation()
console.log(location.latitude, location.longitude)Permission
getLocation may prompt for location permission. If the user denies it, a BridgeErrorCode.PermissionDenied error is thrown.
Vibration
vibrateShort / vibrateLong
Triggers device vibration.
await woo.vibrateShort() // 短振(15ms)
await woo.vibrateLong() // 长振(400ms)Network
getNetworkType
Returns the current network type.
const { networkType } = await woo.getNetworkType()
// 'wifi' | '4g' | '3g' | '2g' | 'none' | 'unknown'Scan
scanCode
Opens the scanner UI.
const result = await woo.scanCode({
scanType: ['qrCode', 'barCode'],
})
console.log(result.result) // 扫码结果
console.log(result.scanType) // 码类型Images
chooseImage
Pick images from the album.
const result = await woo.chooseImage({
count: 3, // 最多选择 3 张
sourceType: ['album', 'camera'],
})
console.log(result.tempFilePaths) // 临时文件路径数组takePhoto
Take a photo.
const result = await woo.takePhoto({
quality: 'high',
})
console.log(result.tempFilePath) // 照片临时路径File upload
uploadFile
Uploads a file to a server.
const result = await woo.uploadFile({
url: 'https://api.example.com/upload',
filePath: tempFilePath,
name: 'file',
header: { Authorization: 'Bearer xxx' },
formData: { type: 'avatar' },
})Map
openMap
Opens system map navigation.
await woo.openMap({
latitude: 39.908860,
longitude: 116.397390,
name: '天安门',
address: '北京市东城区',
})Communication
makePhoneCall
Dials a phone number.
await woo.makePhoneCall({ phoneNumber: '10086' })Screen
setScreenOrientation / getScreenOrientation
Get or set screen orientation.
await woo.setScreenOrientation({ orientation: 'landscape' })
const { orientation } = await woo.getScreenOrientation()onScreenOrientationChange
Listen for orientation changes.
woo.onScreenOrientationChange((result) => {
console.log('屏幕方向:', result.orientation)
})setScreenBrightness / getScreenBrightness
Get or set screen brightness.
await woo.setScreenBrightness({ value: 0.8 }) // 0~1
const { value } = await woo.getScreenBrightness()keepScreenOn
Keep the screen on.
await woo.keepScreenOn({ keepScreenOn: true })Cross-app
navigateToMiniApp
Navigate to another mini program.
await woo.navigateToMiniApp({
appId: 'target-app-id',
path: '/pages/index/index',
extraData: { from: 'my-app' },
})openWallet
Open the wallet.
await woo.openWallet({ type: 'payment' })API quick reference
| Method | Description | Signature |
|---|---|---|
getSystemInfo | System information | () → Promise<SystemInfo> |
getSystemInfoSync | Synchronous getSystemInfo | () → SystemInfo |
getNetworkType | Current network type | () → Promise<{ networkType }> |
onNetworkStatusChange | Network status events | (callback) → void |
makePhoneCall | Place a call | ({ phoneNumber }) → Promise<void> |
scanCode | Scan a code | ({ scanType? }) → Promise<{ result, scanType }> |
getLocation | Geographic location | ({ type? }) → Promise<{ latitude, longitude, ... }> |
vibrateLong / vibrateShort | Long / short vibration | () → Promise<void> |
getBatteryInfo | Battery status | () → Promise<{ level, isCharging }> |
getScreenBrightness | Get brightness | () → Promise<{ value }> |
setScreenBrightness | Set brightness | ({ value }) → Promise<void> |
openWallet | Open wallet | ({ type }) → Promise<void> |