デバイス(Device)
Device API は、端末のハードウェアやシステム情報にアクセスします。
オンラインで試す
ボタンを押すと JSON やメッセージが表示されます
インポート
ts
import woo from 'mini-sdk'
// 或
import { device } from 'mini-sdk'端末情報
getSystemInfo
システム情報を取得します。
ts
const info = await woo.getSystemInfo()戻り値 GetSystemInfoResult:
| フィールド | 型 | 説明 |
|---|---|---|
platform | string | OS(ios / android / simulator) |
system | string | OS バージョン |
brand | string | 端末ブランド |
model | string | 端末型番 |
screenWidth | number | 画面幅(px) |
screenHeight | number | 画面高さ(px) |
windowWidth | number | 利用可能なウィンドウ幅 |
windowHeight | number | 利用可能なウィンドウ高さ |
statusBarHeight | number | ステータスバー高さ |
language | string | システム言語 |
version | string | ホストアプリのバージョン |
SDKVersion | string | SDK バージョン |
getDeviceId
端末の一意識別子を取得します。
ts
const { deviceId } = await woo.getDeviceId()getDeviceInfo
端末の基本情報を取得します。
ts
const info = await woo.getDeviceInfo()getAppInfo
現在のミニプログラムの情報を取得します。
ts
const info = await woo.getAppInfo()
// { appId, appName, env: 'simulator' | 'production', ... }位置
getLocation
現在の位置を取得します。
ts
const location = await woo.getLocation()
console.log(location.latitude, location.longitude)権限
getLocation では位置情報の利用許可を求めます。ユーザーが拒否すると BridgeErrorCode.PermissionDenied が投げられます。
振動
vibrateShort / vibrateLong
端末のバイブレーションを行います。
ts
await woo.vibrateShort() // 短振(15ms)
await woo.vibrateLong() // 长振(400ms)ネットワーク
getNetworkType
現在の接続種別を取得します。
ts
const { networkType } = await woo.getNetworkType()
// 'wifi' | '4g' | '3g' | '2g' | 'none' | 'unknown'スキャン
scanCode
スキャン画面を起動します。
ts
const result = await woo.scanCode({
scanType: ['qrCode', 'barCode'],
})
console.log(result.result) // 扫码结果
console.log(result.scanType) // 码类型画像
chooseImage
アルバムから画像を選びます。
ts
const result = await woo.chooseImage({
count: 3, // 最多选择 3 张
sourceType: ['album', 'camera'],
})
console.log(result.tempFilePaths) // 临时文件路径数组takePhoto
写真を撮影します。
ts
const result = await woo.takePhoto({
quality: 'high',
})
console.log(result.tempFilePath) // 照片临时路径ファイルアップロード
uploadFile
ファイルをサーバーにアップロードします。
ts
const result = await woo.uploadFile({
url: 'https://api.example.com/upload',
filePath: tempFilePath,
name: 'file',
header: { Authorization: 'Bearer xxx' },
formData: { type: 'avatar' },
})地図
openMap
システムの地図ナビを開きます。
ts
await woo.openMap({
latitude: 39.908860,
longitude: 116.397390,
name: '天安门',
address: '北京市东城区',
})通信
makePhoneCall
電話をかけます。
ts
await woo.makePhoneCall({ phoneNumber: '10086' })画面
setScreenOrientation / getScreenOrientation
画面の向きを設定・取得します。
ts
await woo.setScreenOrientation({ orientation: 'landscape' })
const { orientation } = await woo.getScreenOrientation()onScreenOrientationChange
向きの変化を監視します。
ts
woo.onScreenOrientationChange((result) => {
console.log('屏幕方向:', result.orientation)
})setScreenBrightness / getScreenBrightness
明るさを設定・取得します。
ts
await woo.setScreenBrightness({ value: 0.8 }) // 0~1
const { value } = await woo.getScreenBrightness()keepScreenOn
画面常時点灯を行います。
ts
await woo.keepScreenOn({ keepScreenOn: true })アプリ間
navigateToMiniApp
別のミニプログラムへ遷移します。
ts
await woo.navigateToMiniApp({
appId: 'target-app-id',
path: '/pages/index/index',
extraData: { from: 'my-app' },
})openWallet
ウォレットを開きます。
ts
await woo.openWallet({ type: 'payment' })API 早見表
| メソッド | 説明 | シグネチャ |
|---|---|---|
getSystemInfo | システム情報 | () → Promise<SystemInfo> |
getSystemInfoSync | 同期で取得 | () → SystemInfo |
getNetworkType | ネット種別 | () → Promise<{ networkType }> |
onNetworkStatusChange | 接続の変化 | (callback) → void |
makePhoneCall | 電話をかける | ({ phoneNumber }) → Promise<void> |
scanCode | コードスキャン | ({ scanType? }) → Promise<{ result, scanType }> |
getLocation | 位置を取得 | ({ type? }) → Promise<{ latitude, longitude, ... }> |
vibrateLong / vibrateShort | 長/短の振動 | () → Promise<void> |
getBatteryInfo | バッテリー | () → Promise<{ level, isCharging }> |
getScreenBrightness | 明るさ取得 | () → Promise<{ value }> |
setScreenBrightness | 明るさ設定 | ({ value }) → Promise<void> |
openWallet | ウォレット起動 | ({ type }) → Promise<void> |