ota-native-bridge 1.3.0 → 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 CHANGED
@@ -49,6 +49,7 @@ 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()` |
53
54
  | 用资源包里的图换桌面图标 | `Icon.setFromResource({ path: 'icons/app-icon.png' })`(Android 8+;iOS / Harmony 返回失败) |
54
55
  | 加密 Client API 请求 | `Crypto.postEncrypted(url, plain, pem)` |
@@ -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) {
@@ -4,4 +4,4 @@ exports.SDK_VERSION = exports.PACKAGE_NAME = void 0;
4
4
  /** npm 包名(与 package.json name 保持一致) */
5
5
  exports.PACKAGE_NAME = 'ota-native-bridge';
6
6
  /** OTA Native Bridge SDK 版本(与 package.json version 保持一致) */
7
- exports.SDK_VERSION = '1.3.0';
7
+ exports.SDK_VERSION = '1.4.0';
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>;
@@ -208,7 +213,7 @@ export declare const Native: {
208
213
  readonly Push: {
209
214
  getToken(callback?: import("./runtime").NativeCallback<import("./types").PushTokenResult>): Promise<import("./types").PushTokenResult>;
210
215
  };
211
- readonly sdkVersion: "1.3.0";
216
+ readonly sdkVersion: "1.4.0";
212
217
  readonly getPlatform: typeof getPlatform;
213
218
  readonly isNativePlatform: typeof isNativePlatform;
214
219
  readonly isNativeBridgeAvailable: typeof isNativeBridgeAvailable;
@@ -265,6 +270,11 @@ export declare const Native: {
265
270
  getOrientation(callback?: import("./runtime").NativeCallback<import("./types").OrientationInfo>): Promise<import("./types").OrientationInfo>;
266
271
  getLockStatus(callback?: import("./runtime").NativeCallback<import("./types").LockStatus>): Promise<import("./types").LockStatus>;
267
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>;
268
278
  };
269
279
  readonly Config: {
270
280
  getNativeConfig(callback?: import("./runtime").NativeCallback<import("./types").NativeFeatureConfig>): Promise<import("./types").NativeFeatureConfig>;
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, 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';
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>;
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) {
package/dist/types.d.ts CHANGED
@@ -269,6 +269,21 @@ export interface SetNativeFeaturesOptions {
269
269
  /** 嵌套主题对象,便于与配置文件结构一致 */
270
270
  theme?: SetAppThemeOptions;
271
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
+ }
272
287
  export interface DeviceInfo {
273
288
  brand: string;
274
289
  manufacturer: string;
package/dist/version.d.ts CHANGED
@@ -1,4 +1,4 @@
1
1
  /** npm 包名(与 package.json name 保持一致) */
2
2
  export declare const PACKAGE_NAME = "ota-native-bridge";
3
3
  /** OTA Native Bridge SDK 版本(与 package.json version 保持一致) */
4
- export declare const SDK_VERSION = "1.3.0";
4
+ export declare const SDK_VERSION = "1.4.0";
package/dist/version.js CHANGED
@@ -1,4 +1,4 @@
1
1
  /** npm 包名(与 package.json name 保持一致) */
2
2
  export const PACKAGE_NAME = 'ota-native-bridge';
3
3
  /** OTA Native Bridge SDK 版本(与 package.json version 保持一致) */
4
- export const SDK_VERSION = '1.3.0';
4
+ export const SDK_VERSION = '1.4.0';
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 })` |
@@ -927,7 +928,45 @@ Device.getInfo().then(console.log);
927
928
  }
928
929
  ```
929
930
 
930
- > iOS 可能不含 `androidId`;Harmony 字段名与系统能力对齐。`androidId` 仅在合规开关允许时返回。
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
+ ```
931
970
 
932
971
  #### `Device.getScreenInfo()`
933
972
 
@@ -1110,9 +1149,146 @@ Viewport.getWindowInfo().then(console.log);
1110
1149
 
1111
1150
  ### 7.3 桌面图标
1112
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
+
1113
1290
  ```typescript
1114
1291
  Icon.list().then(console.log);
1115
- // 返回示例:
1116
1292
  // {
1117
1293
  // "icons": [
1118
1294
  // { "id": "default", "label": "默认" },
@@ -1132,36 +1308,36 @@ Icon.list().then(console.log);
1132
1308
  // }
1133
1309
 
1134
1310
  Icon.get().then(console.log);
1135
- // 返回示例:同 current 对象
1311
+ // 返回示例:同 current
1136
1312
 
1137
1313
  Icon.set({ iconId: 'alt1' }).then(console.log);
1138
- // 返回示例:{ "success": true, "iconId": "alt1", "message": "ok", "requiresLauncherRefresh": false }
1314
+ // { "success": true, "iconId": "alt1", "message": "ok", "requiresLauncherRefresh": false }
1315
+ ```
1139
1316
 
1140
- Icon.setFromUrl({ url: 'https://cdn.example.com/icon.png' }).then(console.log);
1141
- // 返回示例:{ "success": true, "iconId": "custom", "message": "ok" }
1317
+ `launcherEntryCount` 应为 `1`。大于 `1` 表示桌面留过多余快捷方式,需要用户长按删掉。预置槽切换请用 Release 包;Debug 包调用 `Icon.set` 会失败。
1142
1318
 
1143
- Icon.setFromBase64({ base64: 'iVBORw0KGgo...' }).then(console.log);
1144
- // 返回示例:{ "success": true, "iconId": "custom", "message": "ok" }
1319
+ 从默认图标第一次切到 `alt1` 时应用不会退出。返回 `pendingBackgroundFinalize: true` 时,按 Home 后旧入口才会关掉。
1145
1320
 
1146
- Icon.setFromResource({ path: 'icons/app-icon.png' }).then(console.log);
1147
- // Android 11+:
1148
- // { "success": true, "iconId": "custom", "message": "ok", "requiresLauncherRefresh": true, "pendingPinConfirmation": false }
1149
- // Android 8–10,系统确认框还在等用户点:
1150
- // { "success": true, "iconId": "custom", "message": "Confirm the new home screen icon.", "pendingPinConfirmation": true }
1151
- ```
1321
+ #### 远程图和 Base64
1152
1322
 
1153
- `path` 是前端资源包内的相对路径,不要带 `www/` 前缀,也不要包含 `..`。壳解密 `www.pkg` 后按这个路径取图(热更新包优先于安装包内置资源)。
1323
+ 这两条和 `setFromResource` 一样,只在 Android 上把像素换成桌面图标。图不在资源包里时再用。
1154
1324
 
1155
- | 系统 | 行为 |
1156
- |------|------|
1157
- | Android 11+ | 直接盖住当前桌面入口,不新增图标,没有系统确认框 |
1158
- | Android 8–10 | 弹出一次系统确认。用户允许后,按 Home 回到桌面,原来的启动入口会被收起,只留新图标。同一张图之后再换不再弹框。`pendingPinConfirmation: true` 表示还在等这次确认 |
1159
- | iOS | 返回 `success: false`。只能用 `Icon.set` 在打包时烤入的备用图标之间切换 |
1160
- | HarmonyOS | 返回 `success: false`。运行时不能改桌面图标 |
1325
+ ```typescript
1326
+ Icon.setFromUrl({ url: 'https://cdn.example.com/icon.png' }).then(console.log);
1327
+ // { "success": true, "iconId": "custom", "message": "ok" }
1328
+
1329
+ Icon.setFromBase64({ base64: 'iVBORw0KGgo...' }).then(console.log);
1330
+ // { "success": true, "iconId": "custom", "message": "ok" }
1331
+ ```
1161
1332
 
1162
- `Icon.get()` 的 `supportsCustomFromResource`:Android 11+ 为 `true`;Android 8–10 在当前桌面支持固定快捷方式时为 `true`。
1333
+ #### 各系统实际效果
1163
1334
 
1164
- 资源包 `app_config.json` 可写 `"desktopIcon": "icons/app-icon.png"`。安装资源包后 Android 会自动套用;Android 11+ 在冷启动时也会套用。同一份资源包只自动套用一次,之后前端再调用 `Icon.setFromResource` 选其他图,下一次冷启动不会把它盖掉。Android 8–10 的冷启动不会再弹确认框,只在图标已经固定过时静默更新。
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` | 运行时不能改,需重新出安装包 |
1165
1341
 
1166
1342
  ### 7.4 通知与角标
1167
1343
 
@@ -1499,6 +1675,9 @@ A:管理后台「公共接口」可单独关闭端点;与 Bridge 无关,
1499
1675
  **Q:TypeScript 提示找不到类型?**
1500
1676
  A:执行 `npm run build` 生成 `dist/*.d.ts`,或确认依赖版本已包含类型文件。
1501
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
+
1502
1681
  ---
1503
1682
 
1504
1683
  ## 11. 相关文档
@@ -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 = {
@@ -366,7 +371,7 @@
366
371
  };
367
372
 
368
373
  global.Native = {
369
- sdkVersion: '1.3.0',
374
+ sdkVersion: '1.4.0',
370
375
  getPlatform: getPlatform,
371
376
  isNativePlatform: isNativePlatform,
372
377
  isNativeBridgeAvailable: function () { return !!getNativeMessenger(); },
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ota-native-bridge",
3
- "version": "1.3.0",
3
+ "version": "1.4.0",
4
4
  "description": "App OTA WebView 壳应用跨平台 Native Bridge TypeScript SDK(Android / iOS / HarmonyOS)",
5
5
  "keywords": [
6
6
  "ota",