Skip to content

Device

The Device API exposes hardware and system information.

Try it online

getSystemInfogetNetworkTypegetLocation
Short vibrateLong vibratescanCode

Click a button to show JSON or a message here

Device API demo

System info, network, location, vibration, and scan. Vibration and some actions log to the SDK panel in the corner.

Import

ts
import woo from 'mini-sdk'
// 或
import { device } from 'mini-sdk'

Device information

getSystemInfo

Returns system information.

ts
const info = await woo.getSystemInfo()

Return value GetSystemInfoResult:

FieldTypeDescription
platformstringOS (ios / android / simulator)
systemstringOS version
brandstringDevice brand
modelstringDevice model
screenWidthnumberScreen width (px)
screenHeightnumberScreen height (px)
windowWidthnumberUsable window width
windowHeightnumberUsable window height
statusBarHeightnumberStatus bar height
languagestringSystem language
versionstringHost app version
SDKVersionstringSDK version

getDeviceId

Returns a stable device identifier.

ts
const { deviceId } = await woo.getDeviceId()

getDeviceInfo

Returns basic device information.

ts
const info = await woo.getDeviceInfo()

getAppInfo

Returns the current mini program’s app information.

ts
const info = await woo.getAppInfo()
// { appId, appName, env: 'simulator' | 'production', ... }

Location

getLocation

Gets the current geographic location.

ts
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.

ts
await woo.vibrateShort()  // 短振(15ms)
await woo.vibrateLong()   // 长振(400ms)

Network

getNetworkType

Returns the current network type.

ts
const { networkType } = await woo.getNetworkType()
// 'wifi' | '4g' | '3g' | '2g' | 'none' | 'unknown'

Scan

scanCode

Opens the scanner UI.

ts
const result = await woo.scanCode({
  scanType: ['qrCode', 'barCode'],
})
console.log(result.result) // 扫码结果
console.log(result.scanType) // 码类型

Images

chooseImage

Pick images from the album.

ts
const result = await woo.chooseImage({
  count: 3,       // 最多选择 3 张
  sourceType: ['album', 'camera'],
})
console.log(result.tempFilePaths) // 临时文件路径数组

takePhoto

Take a photo.

ts
const result = await woo.takePhoto({
  quality: 'high',
})
console.log(result.tempFilePath) // 照片临时路径

File upload

uploadFile

Uploads a file to a server.

ts
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.

ts
await woo.openMap({
  latitude: 39.908860,
  longitude: 116.397390,
  name: '天安门',
  address: '北京市东城区',
})

Communication

makePhoneCall

Dials a phone number.

ts
await woo.makePhoneCall({ phoneNumber: '10086' })

Screen

setScreenOrientation / getScreenOrientation

Get or set screen orientation.

ts
await woo.setScreenOrientation({ orientation: 'landscape' })

const { orientation } = await woo.getScreenOrientation()

onScreenOrientationChange

Listen for orientation changes.

ts
woo.onScreenOrientationChange((result) => {
  console.log('屏幕方向:', result.orientation)
})

setScreenBrightness / getScreenBrightness

Get or set screen brightness.

ts
await woo.setScreenBrightness({ value: 0.8 }) // 0~1

const { value } = await woo.getScreenBrightness()

keepScreenOn

Keep the screen on.

ts
await woo.keepScreenOn({ keepScreenOn: true })

Cross-app

Navigate to another mini program.

ts
await woo.navigateToMiniApp({
  appId: 'target-app-id',
  path: '/pages/index/index',
  extraData: { from: 'my-app' },
})

openWallet

Open the wallet.

ts
await woo.openWallet({ type: 'payment' })

API quick reference

MethodDescriptionSignature
getSystemInfoSystem information() → Promise<SystemInfo>
getSystemInfoSyncSynchronous getSystemInfo() → SystemInfo
getNetworkTypeCurrent network type() → Promise<{ networkType }>
onNetworkStatusChangeNetwork status events(callback) → void
makePhoneCallPlace a call({ phoneNumber }) → Promise<void>
scanCodeScan a code({ scanType? }) → Promise<{ result, scanType }>
getLocationGeographic location({ type? }) → Promise<{ latitude, longitude, ... }>
vibrateLong / vibrateShortLong / short vibration() → Promise<void>
getBatteryInfoBattery status() → Promise<{ level, isCharging }>
getScreenBrightnessGet brightness() → Promise<{ value }>
setScreenBrightnessSet brightness({ value }) → Promise<void>
openWalletOpen wallet({ type }) → Promise<void>

MiniDev Studio — Mini-app Development Toolkit