ota-native-bridge 1.2.1 → 1.4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +2 -0
- package/dist/cjs/plugins.js +19 -0
- package/dist/cjs/version.js +1 -1
- package/dist/native.d.ts +13 -1
- package/dist/plugins.d.ts +8 -1
- package/dist/plugins.js +19 -0
- package/dist/types.d.ts +21 -0
- package/dist/version.d.ts +1 -1
- package/dist/version.js +1 -1
- package/docs/USAGE.md +212 -11
- package/ota-native-bridge.js +9 -3
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -49,7 +49,9 @@ if (Native.isNativePlatform()) {
|
|
|
49
49
|
| 支付 / 评分 | `Payment.pay({ url })` / `Store.requestReview()` |
|
|
50
50
|
| 推送 token | `Push.getToken()` |
|
|
51
51
|
| 全屏播视频 | `Media.playVideo({ url, title })` |
|
|
52
|
+
| 读设备标识 | `Device.getIdentifiers()`(须 `collectDeviceIdsAfterConsent`) |
|
|
52
53
|
| 读分辨率 / 方向 / 锁屏 | `Device.getScreenInfo()` / `getOrientation()` / `getLockStatus()` |
|
|
54
|
+
| 用资源包里的图换桌面图标 | `Icon.setFromResource({ path: 'icons/app-icon.png' })`(Android 8+;iOS / Harmony 返回失败) |
|
|
53
55
|
| 加密 Client API 请求 | `Crypto.postEncrypted(url, plain, pem)` |
|
|
54
56
|
|
|
55
57
|
## OTA 服务端地址
|
package/dist/cjs/plugins.js
CHANGED
|
@@ -48,6 +48,21 @@ exports.Device = {
|
|
|
48
48
|
getSystemInfo(callback) {
|
|
49
49
|
return (0, runtime_1.withCallback)((0, runtime_1.invokeNative)('getSystemInfo'), callback);
|
|
50
50
|
},
|
|
51
|
+
getAndroidId(callback) {
|
|
52
|
+
return (0, runtime_1.withCallback)((0, runtime_1.invokeNative)('getAndroidId'), callback);
|
|
53
|
+
},
|
|
54
|
+
getImei(callback) {
|
|
55
|
+
return (0, runtime_1.withCallback)((0, runtime_1.invokeNative)('getImei'), callback);
|
|
56
|
+
},
|
|
57
|
+
getDeviceSerial(callback) {
|
|
58
|
+
return (0, runtime_1.withCallback)((0, runtime_1.invokeNative)('getDeviceSerial'), callback);
|
|
59
|
+
},
|
|
60
|
+
getIdentifiers(callback) {
|
|
61
|
+
return (0, runtime_1.withCallback)((0, runtime_1.invokeNative)('getDeviceIdentifiers'), callback);
|
|
62
|
+
},
|
|
63
|
+
requestPhoneStatePermission(callback) {
|
|
64
|
+
return (0, runtime_1.withCallback)((0, runtime_1.invokeNative)('requestPhoneStatePermission'), callback);
|
|
65
|
+
},
|
|
51
66
|
};
|
|
52
67
|
exports.Config = {
|
|
53
68
|
getNativeConfig(callback) {
|
|
@@ -81,6 +96,10 @@ exports.Icon = {
|
|
|
81
96
|
setFromBase64(options, callback) {
|
|
82
97
|
return (0, runtime_1.withCallback)((0, runtime_1.invokeNative)('setAppIconFromBase64', { ...options }), callback);
|
|
83
98
|
},
|
|
99
|
+
/** 用前端资源包内的图片替换桌面图标。Android 8+ 生效(8–10 会弹出系统确认);iOS / Harmony 返回 success: false。 */
|
|
100
|
+
setFromResource(options, callback) {
|
|
101
|
+
return (0, runtime_1.withCallback)((0, runtime_1.invokeNative)('setAppIconFromResource', { ...options }), callback);
|
|
102
|
+
},
|
|
84
103
|
};
|
|
85
104
|
exports.Viewport = {
|
|
86
105
|
getSafeAreaInsets(callback) {
|
package/dist/cjs/version.js
CHANGED
package/dist/native.d.ts
CHANGED
|
@@ -59,6 +59,11 @@ export declare const Native: {
|
|
|
59
59
|
getOrientation(callback?: import("./runtime").NativeCallback<import("./types").OrientationInfo>): Promise<import("./types").OrientationInfo>;
|
|
60
60
|
getLockStatus(callback?: import("./runtime").NativeCallback<import("./types").LockStatus>): Promise<import("./types").LockStatus>;
|
|
61
61
|
getSystemInfo(callback?: import("./runtime").NativeCallback<import("./types").SystemInfo>): Promise<import("./types").SystemInfo>;
|
|
62
|
+
getAndroidId(callback?: import("./runtime").NativeCallback<Pick<import("./types").DeviceIdentifiers, "collectAllowed" | "androidId">>): Promise<Pick<import("./types").DeviceIdentifiers, "collectAllowed" | "androidId">>;
|
|
63
|
+
getImei(callback?: import("./runtime").NativeCallback<Pick<import("./types").DeviceIdentifiers, "collectAllowed" | "phoneStatePermissionGranted" | "imei">>): Promise<Pick<import("./types").DeviceIdentifiers, "collectAllowed" | "phoneStatePermissionGranted" | "imei">>;
|
|
64
|
+
getDeviceSerial(callback?: import("./runtime").NativeCallback<Pick<import("./types").DeviceIdentifiers, "collectAllowed" | "phoneStatePermissionGranted" | "serial">>): Promise<Pick<import("./types").DeviceIdentifiers, "collectAllowed" | "phoneStatePermissionGranted" | "serial">>;
|
|
65
|
+
getIdentifiers(callback?: import("./runtime").NativeCallback<import("./types").DeviceIdentifiers>): Promise<import("./types").DeviceIdentifiers>;
|
|
66
|
+
requestPhoneStatePermission(callback?: import("./runtime").NativeCallback<import("./types").PhoneStatePermissionResult>): Promise<import("./types").PhoneStatePermissionResult>;
|
|
62
67
|
};
|
|
63
68
|
readonly Config: {
|
|
64
69
|
getNativeConfig(callback?: import("./runtime").NativeCallback<import("./types").NativeFeatureConfig>): Promise<import("./types").NativeFeatureConfig>;
|
|
@@ -79,6 +84,7 @@ export declare const Native: {
|
|
|
79
84
|
data?: string;
|
|
80
85
|
base64?: string;
|
|
81
86
|
}, callback?: import("./runtime").NativeCallback<import("./types").SetAppIconResult>): Promise<import("./types").SetAppIconResult>;
|
|
87
|
+
setFromResource(options: import("./types").SetAppIconFromResourceOptions, callback?: import("./runtime").NativeCallback<import("./types").SetAppIconResult>): Promise<import("./types").SetAppIconResult>;
|
|
82
88
|
};
|
|
83
89
|
readonly Viewport: {
|
|
84
90
|
getSafeAreaInsets(callback?: import("./runtime").NativeCallback<import("./types").SafeAreaInsets>): Promise<import("./types").SafeAreaInsets>;
|
|
@@ -207,7 +213,7 @@ export declare const Native: {
|
|
|
207
213
|
readonly Push: {
|
|
208
214
|
getToken(callback?: import("./runtime").NativeCallback<import("./types").PushTokenResult>): Promise<import("./types").PushTokenResult>;
|
|
209
215
|
};
|
|
210
|
-
readonly sdkVersion: "1.
|
|
216
|
+
readonly sdkVersion: "1.4.0";
|
|
211
217
|
readonly getPlatform: typeof getPlatform;
|
|
212
218
|
readonly isNativePlatform: typeof isNativePlatform;
|
|
213
219
|
readonly isNativeBridgeAvailable: typeof isNativeBridgeAvailable;
|
|
@@ -264,6 +270,11 @@ export declare const Native: {
|
|
|
264
270
|
getOrientation(callback?: import("./runtime").NativeCallback<import("./types").OrientationInfo>): Promise<import("./types").OrientationInfo>;
|
|
265
271
|
getLockStatus(callback?: import("./runtime").NativeCallback<import("./types").LockStatus>): Promise<import("./types").LockStatus>;
|
|
266
272
|
getSystemInfo(callback?: import("./runtime").NativeCallback<import("./types").SystemInfo>): Promise<import("./types").SystemInfo>;
|
|
273
|
+
getAndroidId(callback?: import("./runtime").NativeCallback<Pick<import("./types").DeviceIdentifiers, "collectAllowed" | "androidId">>): Promise<Pick<import("./types").DeviceIdentifiers, "collectAllowed" | "androidId">>;
|
|
274
|
+
getImei(callback?: import("./runtime").NativeCallback<Pick<import("./types").DeviceIdentifiers, "collectAllowed" | "phoneStatePermissionGranted" | "imei">>): Promise<Pick<import("./types").DeviceIdentifiers, "collectAllowed" | "phoneStatePermissionGranted" | "imei">>;
|
|
275
|
+
getDeviceSerial(callback?: import("./runtime").NativeCallback<Pick<import("./types").DeviceIdentifiers, "collectAllowed" | "phoneStatePermissionGranted" | "serial">>): Promise<Pick<import("./types").DeviceIdentifiers, "collectAllowed" | "phoneStatePermissionGranted" | "serial">>;
|
|
276
|
+
getIdentifiers(callback?: import("./runtime").NativeCallback<import("./types").DeviceIdentifiers>): Promise<import("./types").DeviceIdentifiers>;
|
|
277
|
+
requestPhoneStatePermission(callback?: import("./runtime").NativeCallback<import("./types").PhoneStatePermissionResult>): Promise<import("./types").PhoneStatePermissionResult>;
|
|
267
278
|
};
|
|
268
279
|
readonly Config: {
|
|
269
280
|
getNativeConfig(callback?: import("./runtime").NativeCallback<import("./types").NativeFeatureConfig>): Promise<import("./types").NativeFeatureConfig>;
|
|
@@ -284,6 +295,7 @@ export declare const Native: {
|
|
|
284
295
|
data?: string;
|
|
285
296
|
base64?: string;
|
|
286
297
|
}, callback?: import("./runtime").NativeCallback<import("./types").SetAppIconResult>): Promise<import("./types").SetAppIconResult>;
|
|
298
|
+
setFromResource(options: import("./types").SetAppIconFromResourceOptions, callback?: import("./runtime").NativeCallback<import("./types").SetAppIconResult>): Promise<import("./types").SetAppIconResult>;
|
|
287
299
|
};
|
|
288
300
|
readonly Viewport: {
|
|
289
301
|
getSafeAreaInsets(callback?: import("./runtime").NativeCallback<import("./types").SafeAreaInsets>): Promise<import("./types").SafeAreaInsets>;
|
package/dist/plugins.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { type NativeCallback } from './runtime';
|
|
2
|
-
import type { AppChannelCodes, AppIconState, AppIconsResult, AppInfo, AppInstalledResult, AppUpdateTriggerResult, ApkUpdateResult, CheckAppUpdateOptions, CheckAppsInstalledResult, DeviceInfo, InstallAppPackageOptions, InstallAppPackageResult, InstallResourcePackageOptions, InstallResourcePackageResult, LaunchAppOptions, LaunchAppResult, LocationPermissionResult, LocationResult, LocationStatus, LocationWatchResult, LockStatus, NativeFeatureConfig, NotificationOptions, OpenInBrowserOptions, OpenInBrowserResult, OrientationInfo, PlayVideoOptions, PlayVideoResult, HttpRequestOptions, HttpRequestResult, ResourceUpdateResult, SafeAreaInsets, ScreenInfo, SetAppIconOptions, SetAppIconResult, SetAppThemeOptions, SetNativeFeaturesOptions, SystemInfo, ThemeConfig, VideoPlayerStatus, WindowInfo, AdapterState, BiometricStatus, BrightnessState, CalendarEventOptions, CaptureResult, ClipboardResult, ContactResult, FlashlightState, MotionReading, NativeOk, PaymentOptions, PaymentResult, PedometerResult, PickerResult, PushTokenResult, RecorderResult, ReviewResult, ScanResult, ShareOptions, VolumeState } from './types';
|
|
2
|
+
import type { AppChannelCodes, AppIconState, AppIconsResult, AppInfo, AppInstalledResult, AppUpdateTriggerResult, ApkUpdateResult, CheckAppUpdateOptions, CheckAppsInstalledResult, DeviceIdentifiers, DeviceInfo, PhoneStatePermissionResult, InstallAppPackageOptions, InstallAppPackageResult, InstallResourcePackageOptions, InstallResourcePackageResult, LaunchAppOptions, LaunchAppResult, LocationPermissionResult, LocationResult, LocationStatus, LocationWatchResult, LockStatus, NativeFeatureConfig, NotificationOptions, OpenInBrowserOptions, OpenInBrowserResult, OrientationInfo, PlayVideoOptions, PlayVideoResult, HttpRequestOptions, HttpRequestResult, ResourceUpdateResult, SafeAreaInsets, ScreenInfo, SetAppIconFromResourceOptions, SetAppIconOptions, SetAppIconResult, SetAppThemeOptions, SetNativeFeaturesOptions, SystemInfo, ThemeConfig, VideoPlayerStatus, WindowInfo, AdapterState, BiometricStatus, BrightnessState, CalendarEventOptions, CaptureResult, ClipboardResult, ContactResult, FlashlightState, MotionReading, NativeOk, PaymentOptions, PaymentResult, PedometerResult, PickerResult, PushTokenResult, RecorderResult, ReviewResult, ScanResult, ShareOptions, VolumeState } from './types';
|
|
3
3
|
export declare const App: {
|
|
4
4
|
ping(callback?: NativeCallback<{
|
|
5
5
|
pong: boolean;
|
|
@@ -21,6 +21,11 @@ export declare const Device: {
|
|
|
21
21
|
getOrientation(callback?: NativeCallback<OrientationInfo>): Promise<OrientationInfo>;
|
|
22
22
|
getLockStatus(callback?: NativeCallback<LockStatus>): Promise<LockStatus>;
|
|
23
23
|
getSystemInfo(callback?: NativeCallback<SystemInfo>): Promise<SystemInfo>;
|
|
24
|
+
getAndroidId(callback?: NativeCallback<Pick<DeviceIdentifiers, "collectAllowed" | "androidId">>): Promise<Pick<DeviceIdentifiers, "collectAllowed" | "androidId">>;
|
|
25
|
+
getImei(callback?: NativeCallback<Pick<DeviceIdentifiers, "collectAllowed" | "phoneStatePermissionGranted" | "imei">>): Promise<Pick<DeviceIdentifiers, "collectAllowed" | "phoneStatePermissionGranted" | "imei">>;
|
|
26
|
+
getDeviceSerial(callback?: NativeCallback<Pick<DeviceIdentifiers, "collectAllowed" | "phoneStatePermissionGranted" | "serial">>): Promise<Pick<DeviceIdentifiers, "collectAllowed" | "phoneStatePermissionGranted" | "serial">>;
|
|
27
|
+
getIdentifiers(callback?: NativeCallback<DeviceIdentifiers>): Promise<DeviceIdentifiers>;
|
|
28
|
+
requestPhoneStatePermission(callback?: NativeCallback<PhoneStatePermissionResult>): Promise<PhoneStatePermissionResult>;
|
|
24
29
|
};
|
|
25
30
|
export declare const Config: {
|
|
26
31
|
getNativeConfig(callback?: NativeCallback<NativeFeatureConfig>): Promise<NativeFeatureConfig>;
|
|
@@ -41,6 +46,8 @@ export declare const Icon: {
|
|
|
41
46
|
data?: string;
|
|
42
47
|
base64?: string;
|
|
43
48
|
}, callback?: NativeCallback<SetAppIconResult>): Promise<SetAppIconResult>;
|
|
49
|
+
/** 用前端资源包内的图片替换桌面图标。Android 8+ 生效(8–10 会弹出系统确认);iOS / Harmony 返回 success: false。 */
|
|
50
|
+
setFromResource(options: SetAppIconFromResourceOptions, callback?: NativeCallback<SetAppIconResult>): Promise<SetAppIconResult>;
|
|
44
51
|
};
|
|
45
52
|
export declare const Viewport: {
|
|
46
53
|
getSafeAreaInsets(callback?: NativeCallback<SafeAreaInsets>): Promise<SafeAreaInsets>;
|
package/dist/plugins.js
CHANGED
|
@@ -45,6 +45,21 @@ export const Device = {
|
|
|
45
45
|
getSystemInfo(callback) {
|
|
46
46
|
return withCallback(invokeNative('getSystemInfo'), callback);
|
|
47
47
|
},
|
|
48
|
+
getAndroidId(callback) {
|
|
49
|
+
return withCallback(invokeNative('getAndroidId'), callback);
|
|
50
|
+
},
|
|
51
|
+
getImei(callback) {
|
|
52
|
+
return withCallback(invokeNative('getImei'), callback);
|
|
53
|
+
},
|
|
54
|
+
getDeviceSerial(callback) {
|
|
55
|
+
return withCallback(invokeNative('getDeviceSerial'), callback);
|
|
56
|
+
},
|
|
57
|
+
getIdentifiers(callback) {
|
|
58
|
+
return withCallback(invokeNative('getDeviceIdentifiers'), callback);
|
|
59
|
+
},
|
|
60
|
+
requestPhoneStatePermission(callback) {
|
|
61
|
+
return withCallback(invokeNative('requestPhoneStatePermission'), callback);
|
|
62
|
+
},
|
|
48
63
|
};
|
|
49
64
|
export const Config = {
|
|
50
65
|
getNativeConfig(callback) {
|
|
@@ -78,6 +93,10 @@ export const Icon = {
|
|
|
78
93
|
setFromBase64(options, callback) {
|
|
79
94
|
return withCallback(invokeNative('setAppIconFromBase64', { ...options }), callback);
|
|
80
95
|
},
|
|
96
|
+
/** 用前端资源包内的图片替换桌面图标。Android 8+ 生效(8–10 会弹出系统确认);iOS / Harmony 返回 success: false。 */
|
|
97
|
+
setFromResource(options, callback) {
|
|
98
|
+
return withCallback(invokeNative('setAppIconFromResource', { ...options }), callback);
|
|
99
|
+
},
|
|
81
100
|
};
|
|
82
101
|
export const Viewport = {
|
|
83
102
|
getSafeAreaInsets(callback) {
|
package/dist/types.d.ts
CHANGED
|
@@ -226,6 +226,8 @@ export interface AppIconState {
|
|
|
226
226
|
customIconPath: string;
|
|
227
227
|
customIconExists: boolean;
|
|
228
228
|
supportsCustomFromUrl: boolean;
|
|
229
|
+
/** Android 8+ 可从资源包换桌面图标(8–10 需系统确认一次);iOS / Harmony 为 false */
|
|
230
|
+
supportsCustomFromResource?: boolean;
|
|
229
231
|
}
|
|
230
232
|
export interface AppIconsResult {
|
|
231
233
|
icons: AppIconOption[];
|
|
@@ -236,6 +238,10 @@ export interface SetAppIconOptions {
|
|
|
236
238
|
/** 与 iconId 等价 */
|
|
237
239
|
icon?: AppIconId;
|
|
238
240
|
}
|
|
241
|
+
/** 资源包内相对路径,例如 `icons/app-icon.png`(相对 www 根,不要带 `www/` 前缀) */
|
|
242
|
+
export interface SetAppIconFromResourceOptions {
|
|
243
|
+
path: string;
|
|
244
|
+
}
|
|
239
245
|
export interface SetAppIconResult {
|
|
240
246
|
success: boolean;
|
|
241
247
|
iconId: AppIconId;
|
|
@@ -263,6 +269,21 @@ export interface SetNativeFeaturesOptions {
|
|
|
263
269
|
/** 嵌套主题对象,便于与配置文件结构一致 */
|
|
264
270
|
theme?: SetAppThemeOptions;
|
|
265
271
|
}
|
|
272
|
+
/** getDeviceIdentifiers / getAndroidId 等;须 store.collectDeviceIdsAfterConsent */
|
|
273
|
+
export interface DeviceIdentifiers {
|
|
274
|
+
collectAllowed: boolean;
|
|
275
|
+
phoneStatePermissionGranted?: boolean;
|
|
276
|
+
/** Android: ANDROID_ID;iOS: IDFV;Harmony: ODID */
|
|
277
|
+
androidId: string;
|
|
278
|
+
imei?: string;
|
|
279
|
+
serial?: string;
|
|
280
|
+
identifierForVendor?: string;
|
|
281
|
+
odid?: string;
|
|
282
|
+
}
|
|
283
|
+
export interface PhoneStatePermissionResult {
|
|
284
|
+
granted: boolean;
|
|
285
|
+
message?: string;
|
|
286
|
+
}
|
|
266
287
|
export interface DeviceInfo {
|
|
267
288
|
brand: string;
|
|
268
289
|
manufacturer: string;
|
package/dist/version.d.ts
CHANGED
package/dist/version.js
CHANGED
package/docs/USAGE.md
CHANGED
|
@@ -50,6 +50,7 @@ if (!Native.isNativePlatform()) {
|
|
|
50
50
|
| 打开网页 | `Browser.open('https://...')` |
|
|
51
51
|
| 读安全区 | `Viewport.getSafeAreaInsets()` |
|
|
52
52
|
| 读设备信息 | `Device.getInfo()` |
|
|
53
|
+
| 读设备标识(ID/IMEI/序列号) | `Device.getIdentifiers()`(须 `collectDeviceIdsAfterConsent`) |
|
|
53
54
|
| 读分辨率 / 方向 / 锁屏 | `Device.getScreenInfo()` / `getOrientation()` / `getLockStatus()` |
|
|
54
55
|
| 发通知 | `Notification.show({ title, body })` |
|
|
55
56
|
| 剪贴板 / 分享 | `Clipboard.set('hi')` / `Share.open({ text, url })` |
|
|
@@ -778,7 +779,8 @@ iOS 对应字段:`apiBaseUrl`、`platformId`、`apiKey`、`autoCheckUpdateOnLa
|
|
|
778
779
|
},
|
|
779
780
|
"update": {
|
|
780
781
|
"useCustomUpdate": false
|
|
781
|
-
}
|
|
782
|
+
},
|
|
783
|
+
"desktopIcon": "icons/app-icon.png"
|
|
782
784
|
}
|
|
783
785
|
```
|
|
784
786
|
|
|
@@ -790,6 +792,7 @@ iOS 对应字段:`apiBaseUrl`、`platformId`、`apiKey`、`autoCheckUpdateOnLa
|
|
|
790
792
|
| `safeArea.enableTop` / `enableBottom` | 头部沉浸式适配 / 底部原生收缩(默认 `true`) |
|
|
791
793
|
| `safeArea.topBackgroundColor` / `bottomBackgroundColor` | 头部/底部安全区色条颜色,留空回退 `theme.backgroundColor` |
|
|
792
794
|
| `theme` / `guide` 等 | 界面与功能开关(**开屏广告不在此配置**,由管理后台 OTA 下发,见 [OTA_PROTOCOL.md](../../docs/OTA_PROTOCOL.md)) |
|
|
795
|
+
| `desktopIcon` | 资源包内桌面图标相对路径(如 `icons/app-icon.png`)。Android 安装资源包后自动套用;Android 11+ 冷启动也会套用。留空则不自动换图标 |
|
|
793
796
|
|
|
794
797
|
### 6.3 `App.getInfo()` 中的 `platform`
|
|
795
798
|
|
|
@@ -925,7 +928,45 @@ Device.getInfo().then(console.log);
|
|
|
925
928
|
}
|
|
926
929
|
```
|
|
927
930
|
|
|
928
|
-
> iOS
|
|
931
|
+
> `androidId` 仅在 `store.collectDeviceIdsAfterConsent: true` 时返回;iOS 为 `identifierForVendor`,Harmony 为 `ODID`。
|
|
932
|
+
|
|
933
|
+
#### `Device.getAndroidId()` / `getImei()` / `getDeviceSerial()` / `getIdentifiers()`
|
|
934
|
+
|
|
935
|
+
三端 **Bridge 方法名一致**(原生:`getAndroidId` / `getImei` / `getDeviceSerial` / `getDeviceIdentifiers`)。须 `app_config.json` → `store.collectDeviceIdsAfterConsent: true`。
|
|
936
|
+
|
|
937
|
+
```javascript
|
|
938
|
+
Device.getIdentifiers().then(function (ids) {
|
|
939
|
+
console.log(ids.collectAllowed, ids.androidId, ids.imei, ids.serial);
|
|
940
|
+
});
|
|
941
|
+
```
|
|
942
|
+
|
|
943
|
+
Android 读取 IMEI / 硬件序列号前建议:
|
|
944
|
+
|
|
945
|
+
```javascript
|
|
946
|
+
Device.requestPhoneStatePermission().then(function () {
|
|
947
|
+
return Device.getImei();
|
|
948
|
+
}).then(console.log);
|
|
949
|
+
```
|
|
950
|
+
|
|
951
|
+
| 平台 | `androidId` 含义 | `imei` / `serial` |
|
|
952
|
+
|------|------------------|-------------------|
|
|
953
|
+
| **Android** | `Settings.Secure.ANDROID_ID` | 需 `READ_PHONE_STATE`;Android 10+ 普通应用常仍为空 |
|
|
954
|
+
| **iOS** | `identifierForVendor`(另返回 `identifierForVendor`) | 不对普通 App 开放,恒为空 |
|
|
955
|
+
| **Harmony** | `ODID`(另返回 `odid`) | IMEI 不开放;`serial` 为 `deviceInfo.serial`,三方 App 常为空 |
|
|
956
|
+
|
|
957
|
+
`requestPhoneStatePermission()` 仅 **Android** 会弹运行时授权;iOS / Harmony 返回 `granted: false` 与说明 `message`。
|
|
958
|
+
|
|
959
|
+
单次返回示例(`getDeviceIdentifiers`):
|
|
960
|
+
|
|
961
|
+
```json
|
|
962
|
+
{
|
|
963
|
+
"collectAllowed": true,
|
|
964
|
+
"phoneStatePermissionGranted": true,
|
|
965
|
+
"androidId": "a1b2c3d4e5f67890",
|
|
966
|
+
"imei": "",
|
|
967
|
+
"serial": ""
|
|
968
|
+
}
|
|
969
|
+
```
|
|
929
970
|
|
|
930
971
|
#### `Device.getScreenInfo()`
|
|
931
972
|
|
|
@@ -1108,9 +1149,146 @@ Viewport.getWindowInfo().then(console.log);
|
|
|
1108
1149
|
|
|
1109
1150
|
### 7.3 桌面图标
|
|
1110
1151
|
|
|
1152
|
+
桌面图标有两条路,不要混用:
|
|
1153
|
+
|
|
1154
|
+
| 方式 | 图从哪来 | 谁来换 | 适用 |
|
|
1155
|
+
|------|----------|--------|------|
|
|
1156
|
+
| 预置槽 | 打包进安装包的 `default` / `alt1` / `alt2` | `Icon.set({ iconId })` | 三端里 Android、iOS 可在已烤入的槽位之间切换 |
|
|
1157
|
+
| 资源包图片 | 前端资源包里的 PNG | `Icon.setFromResource({ path })`,或 `app_config.json` 的 `desktopIcon` | **仅 Android 8+**。iOS、HarmonyOS 会返回失败 |
|
|
1158
|
+
|
|
1159
|
+
资源包图片会换成**当前这一个**桌面图标,不会再在桌面上多出一个同名应用。
|
|
1160
|
+
|
|
1161
|
+
#### 资源包里怎么放
|
|
1162
|
+
|
|
1163
|
+
把正方形 PNG 打进明文 `www.zip`,路径相对包根目录。服务端加密后,这张图在 `www.pkg` 里,`app_config.json` 仍是明文。
|
|
1164
|
+
|
|
1165
|
+
```text
|
|
1166
|
+
www.zip
|
|
1167
|
+
├── app_config.json
|
|
1168
|
+
├── index.html
|
|
1169
|
+
└── icons/
|
|
1170
|
+
├── app-icon.png # 默认桌面图标
|
|
1171
|
+
└── app-icon-festival.png # 可选:活动图标,由页面再切换
|
|
1172
|
+
```
|
|
1173
|
+
|
|
1174
|
+
`app_config.json`:
|
|
1175
|
+
|
|
1176
|
+
```json
|
|
1177
|
+
{
|
|
1178
|
+
"appName": "示例 App",
|
|
1179
|
+
"url": "/",
|
|
1180
|
+
"desktopIcon": "icons/app-icon.png"
|
|
1181
|
+
}
|
|
1182
|
+
```
|
|
1183
|
+
|
|
1184
|
+
| 规则 | 说明 |
|
|
1185
|
+
|------|------|
|
|
1186
|
+
| 路径 | `icons/app-icon.png`。不要写成 `/icons/...`、`www/icons/...`,也不要包含 `..` |
|
|
1187
|
+
| 图片 | 正方形 PNG。建议 512×512 或 1024×1024 |
|
|
1188
|
+
| 自动套用 | `desktopIcon` 非空时,Android 在**安装这份资源包之后**自动换上。同一份 `www.pkg` 只自动套用一次 |
|
|
1189
|
+
| 冷启动 | Android 11+ 若这份包还没套用过,冷启动会再套用一次。Android 8–10 冷启动**不会**再弹确认框,只在图标已经固定过时静默更新 |
|
|
1190
|
+
| 页面再切换 | 用户选了另一张图后调用 `Icon.setFromResource`。下一次冷启动不会用 `desktopIcon` 把这次选择盖掉 |
|
|
1191
|
+
|
|
1192
|
+
壳取图顺序:先解密热更新的 `www.pkg`,再解密安装包内置的 `www.pkg`,最后才看明文 `www/` 目录。
|
|
1193
|
+
|
|
1194
|
+
#### 先看当前系统能不能换
|
|
1195
|
+
|
|
1196
|
+
```typescript
|
|
1197
|
+
import { Icon, Native } from 'ota-native-bridge';
|
|
1198
|
+
|
|
1199
|
+
function applyDesktopIcon(path) {
|
|
1200
|
+
if (!Native.isNativePlatform()) {
|
|
1201
|
+
return;
|
|
1202
|
+
}
|
|
1203
|
+
Icon.get().then((current) => {
|
|
1204
|
+
if (!current.supportsCustomFromResource) {
|
|
1205
|
+
console.log('当前系统不能用资源包图片换桌面图标');
|
|
1206
|
+
return;
|
|
1207
|
+
}
|
|
1208
|
+
Icon.setFromResource({ path: path }).then((result) => {
|
|
1209
|
+
if (!result.success) {
|
|
1210
|
+
console.log(result.message);
|
|
1211
|
+
return;
|
|
1212
|
+
}
|
|
1213
|
+
if (result.pendingPinConfirmation) {
|
|
1214
|
+
console.log('请在系统对话框里允许添加图标');
|
|
1215
|
+
return;
|
|
1216
|
+
}
|
|
1217
|
+
console.log('桌面图标已更新', result.iconId);
|
|
1218
|
+
});
|
|
1219
|
+
});
|
|
1220
|
+
}
|
|
1221
|
+
|
|
1222
|
+
applyDesktopIcon('icons/app-icon.png');
|
|
1223
|
+
```
|
|
1224
|
+
|
|
1225
|
+
`supportsCustomFromResource`:Android 11+ 为 `true`;Android 8–10 只有当前桌面支持固定快捷方式时为 `true`;iOS、HarmonyOS 为 `false` 或不返回该字段。
|
|
1226
|
+
|
|
1227
|
+
#### 用资源包里的图换图标
|
|
1228
|
+
|
|
1229
|
+
```typescript
|
|
1230
|
+
Icon.setFromResource({ path: 'icons/app-icon.png' }).then(console.log);
|
|
1231
|
+
```
|
|
1232
|
+
|
|
1233
|
+
Android 11+ 返回示例:
|
|
1234
|
+
|
|
1235
|
+
```json
|
|
1236
|
+
{
|
|
1237
|
+
"success": true,
|
|
1238
|
+
"iconId": "custom",
|
|
1239
|
+
"message": "Home screen icon updated. Check the home screen.",
|
|
1240
|
+
"requiresLauncherRefresh": true,
|
|
1241
|
+
"pendingBackgroundFinalize": false,
|
|
1242
|
+
"pendingPinConfirmation": false
|
|
1243
|
+
}
|
|
1244
|
+
```
|
|
1245
|
+
|
|
1246
|
+
Android 8–10,系统确认框还在等用户点时:
|
|
1247
|
+
|
|
1248
|
+
```json
|
|
1249
|
+
{
|
|
1250
|
+
"success": true,
|
|
1251
|
+
"iconId": "custom",
|
|
1252
|
+
"message": "Confirm the new home screen icon.",
|
|
1253
|
+
"requiresLauncherRefresh": true,
|
|
1254
|
+
"pendingPinConfirmation": true
|
|
1255
|
+
}
|
|
1256
|
+
```
|
|
1257
|
+
|
|
1258
|
+
用户点允许后,让用户按一次 Home。原来的启动图标会被收起,桌面上只留新图标。同一张快捷方式之后再换图,直接更新,不再弹框。
|
|
1259
|
+
|
|
1260
|
+
| 字段 | 含义 |
|
|
1261
|
+
|------|------|
|
|
1262
|
+
| `success` | 是否已提交换图标。Android 8–10 弹出确认框时也是 `true` |
|
|
1263
|
+
| `iconId` | 成功时为 `custom` |
|
|
1264
|
+
| `pendingPinConfirmation` | `true`:Android 8–10 还在等系统确认,桌面图标尚未换成新图 |
|
|
1265
|
+
| `pendingBackgroundFinalize` | `true`:要等应用退到后台,旧的桌面入口才会关掉 |
|
|
1266
|
+
| `requiresLauncherRefresh` | `true`:回主屏才能看到新图标 |
|
|
1267
|
+
| `message` | 失败原因,或需要用户做的下一步 |
|
|
1268
|
+
|
|
1269
|
+
失败示例(路径不存在,或桌面不支持):
|
|
1270
|
+
|
|
1271
|
+
```json
|
|
1272
|
+
{ "success": false, "iconId": "default", "message": "Icon file not found: icons/app-icon.png" }
|
|
1273
|
+
```
|
|
1274
|
+
|
|
1275
|
+
#### 在几张资源包图片之间切换
|
|
1276
|
+
|
|
1277
|
+
```typescript
|
|
1278
|
+
function chooseIcon(id) {
|
|
1279
|
+
const file = id === 'festival' ? 'icons/app-icon-festival.png' : 'icons/app-icon.png';
|
|
1280
|
+
Icon.setFromResource({ path: file }).then((result) => {
|
|
1281
|
+
if (result.pendingPinConfirmation) {
|
|
1282
|
+
console.log('第一次需要在系统对话框里点允许');
|
|
1283
|
+
}
|
|
1284
|
+
});
|
|
1285
|
+
}
|
|
1286
|
+
```
|
|
1287
|
+
|
|
1288
|
+
#### 查询当前图标和预置槽
|
|
1289
|
+
|
|
1111
1290
|
```typescript
|
|
1112
1291
|
Icon.list().then(console.log);
|
|
1113
|
-
// 返回示例:
|
|
1114
1292
|
// {
|
|
1115
1293
|
// "icons": [
|
|
1116
1294
|
// { "id": "default", "label": "默认" },
|
|
@@ -1124,23 +1302,43 @@ Icon.list().then(console.log);
|
|
|
1124
1302
|
// "launcherEntryCount": 1,
|
|
1125
1303
|
// "customIconPath": "",
|
|
1126
1304
|
// "customIconExists": false,
|
|
1127
|
-
// "supportsCustomFromUrl": true
|
|
1305
|
+
// "supportsCustomFromUrl": true,
|
|
1306
|
+
// "supportsCustomFromResource": true
|
|
1128
1307
|
// }
|
|
1129
1308
|
// }
|
|
1130
1309
|
|
|
1131
1310
|
Icon.get().then(console.log);
|
|
1132
|
-
// 返回示例:同 current
|
|
1311
|
+
// 返回示例:同 current
|
|
1133
1312
|
|
|
1134
1313
|
Icon.set({ iconId: 'alt1' }).then(console.log);
|
|
1135
|
-
//
|
|
1314
|
+
// { "success": true, "iconId": "alt1", "message": "ok", "requiresLauncherRefresh": false }
|
|
1315
|
+
```
|
|
1316
|
+
|
|
1317
|
+
`launcherEntryCount` 应为 `1`。大于 `1` 表示桌面留过多余快捷方式,需要用户长按删掉。预置槽切换请用 Release 包;Debug 包调用 `Icon.set` 会失败。
|
|
1318
|
+
|
|
1319
|
+
从默认图标第一次切到 `alt1` 时应用不会退出。返回 `pendingBackgroundFinalize: true` 时,按 Home 后旧入口才会关掉。
|
|
1320
|
+
|
|
1321
|
+
#### 远程图和 Base64
|
|
1136
1322
|
|
|
1323
|
+
这两条和 `setFromResource` 一样,只在 Android 上把像素换成桌面图标。图不在资源包里时再用。
|
|
1324
|
+
|
|
1325
|
+
```typescript
|
|
1137
1326
|
Icon.setFromUrl({ url: 'https://cdn.example.com/icon.png' }).then(console.log);
|
|
1138
|
-
//
|
|
1327
|
+
// { "success": true, "iconId": "custom", "message": "ok" }
|
|
1139
1328
|
|
|
1140
1329
|
Icon.setFromBase64({ base64: 'iVBORw0KGgo...' }).then(console.log);
|
|
1141
|
-
//
|
|
1330
|
+
// { "success": true, "iconId": "custom", "message": "ok" }
|
|
1142
1331
|
```
|
|
1143
1332
|
|
|
1333
|
+
#### 各系统实际效果
|
|
1334
|
+
|
|
1335
|
+
| 系统 | `setFromResource` | `Icon.set` 预置槽 |
|
|
1336
|
+
|------|-------------------|-------------------|
|
|
1337
|
+
| Android 11+ | 直接盖住当前桌面入口,没有确认框 | 切换已烤入的 `activity-alias` |
|
|
1338
|
+
| Android 8–10 | 系统确认一次后固定快捷方式;按 Home 收起原图标 | 同上 |
|
|
1339
|
+
| iOS | `success: false` | `default` / `alt1` / `alt2`,系统可能再弹一次确认 |
|
|
1340
|
+
| HarmonyOS | `success: false` | 运行时不能改,需重新出安装包 |
|
|
1341
|
+
|
|
1144
1342
|
### 7.4 通知与角标
|
|
1145
1343
|
|
|
1146
1344
|
```typescript
|
|
@@ -1394,8 +1592,8 @@ Push.getToken().then(console.log);
|
|
|
1394
1592
|
| 能力 | Android | iOS | HarmonyOS |
|
|
1395
1593
|
|------|---------|-----|-----------|
|
|
1396
1594
|
| 剪贴板 / 分享 | 已实现 | 已实现 | 已实现 |
|
|
1397
|
-
| 选图 / 拍照 / 选文件 |
|
|
1398
|
-
| 保存相册 | MediaStore | 写入相册(需相册权限) | 系统相册入口,部分机型需业务自行落盘 |
|
|
1595
|
+
| 选图 / 拍照 / 选文件 | 相册始终 `ACTION_PICK`;文件始终 `OPEN_DOCUMENT`;拍照 FileProvider | PHPicker / 相机 / 文档 | PhotoViewPicker / DocumentViewPicker |
|
|
1596
|
+
| 保存相册 | MediaStore(应用专属写入,不需 READ_MEDIA) | 写入相册(需相册权限) | 系统相册入口,部分机型需业务自行落盘 |
|
|
1399
1597
|
| 扫码 | ZXing 全屏扫码 | AVFoundation | Scan Kit |
|
|
1400
1598
|
| 生物识别 | BiometricPrompt | LocalAuthentication(面容/指纹) | 因系统版本差异可能返回未接线提示 |
|
|
1401
1599
|
| 通讯录 / 日历 | 系统选择器 / 插入日历 Intent | CNContactPicker / EKEventEdit | 日历/联系人选择器因 API 版本可能降级 |
|
|
@@ -1406,7 +1604,7 @@ Push.getToken().then(console.log);
|
|
|
1406
1604
|
| 支付 | **不内置**微信/支付宝 SDK,打开 `url`/`payUrl` | 同左 | 同左 |
|
|
1407
1605
|
| 应用内评分 | Play In-App Review | `SKStoreReviewController` | 引导应用市场 |
|
|
1408
1606
|
| 推送 token | 无 FCM;`provider: ota-websocket` | APNs(App ID 须打开 Push) | `ota-websocket` |
|
|
1409
|
-
| 换图标 | `Icon.set
|
|
1607
|
+
| 换图标 | 预置槽 `Icon.set`。资源包图用 `Icon.setFromResource`:Android 11+ 直接覆盖当前入口;Android 8–10 系统确认一次后固定快捷方式 | 只能切 Alternate Icons(`default` / `alt1` / `alt2`)。`setFromResource` 不能改桌面图标 | 运行时不能改桌面图标,`setFromResource` 返回 `success: false` |
|
|
1410
1608
|
| 角标 | ShortcutBadger(看桌面) | `applicationIconBadgeNumber` | `notificationManager.setBadgeNumber` |
|
|
1411
1609
|
| 锁屏 | Keyguard 真实状态 | `isProtectedDataAvailable`(前台近似) | `screenLock`;不支持时 `supported: false` |
|
|
1412
1610
|
|
|
@@ -1477,6 +1675,9 @@ A:管理后台「公共接口」可单独关闭端点;与 Bridge 无关,
|
|
|
1477
1675
|
**Q:TypeScript 提示找不到类型?**
|
|
1478
1676
|
A:执行 `npm run build` 生成 `dist/*.d.ts`,或确认依赖版本已包含类型文件。
|
|
1479
1677
|
|
|
1678
|
+
**Q:`Icon.setFromResource` 调用了但桌面图标没变?**
|
|
1679
|
+
A:先看 `Icon.get()` 的 `supportsCustomFromResource`。iOS 和 HarmonyOS 会返回失败。Android 8–10 若 `pendingPinConfirmation` 为 `true`,需要用户在系统对话框里点允许,再按一次 Home。路径必须是资源包内相对路径,例如 `icons/app-icon.png`,图要打进 `www.zip` 后由服务端加密进 `www.pkg`。
|
|
1680
|
+
|
|
1480
1681
|
---
|
|
1481
1682
|
|
|
1482
1683
|
## 11. 相关文档
|
package/ota-native-bridge.js
CHANGED
|
@@ -122,7 +122,12 @@
|
|
|
122
122
|
getScreenInfo: function (cb) { return withCallback(invokeNative('getScreenInfo'), cb); },
|
|
123
123
|
getOrientation: function (cb) { return withCallback(invokeNative('getOrientation'), cb); },
|
|
124
124
|
getLockStatus: function (cb) { return withCallback(invokeNative('getLockStatus'), cb); },
|
|
125
|
-
getSystemInfo: function (cb) { return withCallback(invokeNative('getSystemInfo'), cb); }
|
|
125
|
+
getSystemInfo: function (cb) { return withCallback(invokeNative('getSystemInfo'), cb); },
|
|
126
|
+
getAndroidId: function (cb) { return withCallback(invokeNative('getAndroidId'), cb); },
|
|
127
|
+
getImei: function (cb) { return withCallback(invokeNative('getImei'), cb); },
|
|
128
|
+
getDeviceSerial: function (cb) { return withCallback(invokeNative('getDeviceSerial'), cb); },
|
|
129
|
+
getIdentifiers: function (cb) { return withCallback(invokeNative('getDeviceIdentifiers'), cb); },
|
|
130
|
+
requestPhoneStatePermission: function (cb) { return withCallback(invokeNative('requestPhoneStatePermission'), cb); }
|
|
126
131
|
};
|
|
127
132
|
|
|
128
133
|
var Config = {
|
|
@@ -140,7 +145,8 @@
|
|
|
140
145
|
get: function (cb) { return withCallback(invokeNative('getAppIcon'), cb); },
|
|
141
146
|
set: function (opts, cb) { return withCallback(invokeNative('setAppIcon', opts), cb); },
|
|
142
147
|
setFromUrl: function (opts, cb) { return withCallback(invokeNative('setAppIconFromUrl', opts), cb); },
|
|
143
|
-
setFromBase64: function (opts, cb) { return withCallback(invokeNative('setAppIconFromBase64', opts), cb); }
|
|
148
|
+
setFromBase64: function (opts, cb) { return withCallback(invokeNative('setAppIconFromBase64', opts), cb); },
|
|
149
|
+
setFromResource: function (opts, cb) { return withCallback(invokeNative('setAppIconFromResource', opts), cb); }
|
|
144
150
|
};
|
|
145
151
|
|
|
146
152
|
var Viewport = {
|
|
@@ -365,7 +371,7 @@
|
|
|
365
371
|
};
|
|
366
372
|
|
|
367
373
|
global.Native = {
|
|
368
|
-
sdkVersion: '1.
|
|
374
|
+
sdkVersion: '1.4.0',
|
|
369
375
|
getPlatform: getPlatform,
|
|
370
376
|
isNativePlatform: isNativePlatform,
|
|
371
377
|
isNativeBridgeAvailable: function () { return !!getNativeMessenger(); },
|