ota-native-bridge 1.3.0 → 1.5.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 +19 -0
- package/dist/version.d.ts +1 -1
- package/dist/version.js +1 -1
- package/docs/USAGE.md +216 -23
- package/ota-native-bridge.js +8 -2
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -49,6 +49,8 @@ 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`) |
|
|
53
|
+
| 读设备序列号 | `Device.getInstallDeviceId()`(壳首次生成,与签名证书无关) |
|
|
52
54
|
| 读分辨率 / 方向 / 锁屏 | `Device.getScreenInfo()` / `getOrientation()` / `getLockStatus()` |
|
|
53
55
|
| 用资源包里的图换桌面图标 | `Icon.setFromResource({ path: 'icons/app-icon.png' })`(Android 8+;iOS / Harmony 返回失败) |
|
|
54
56
|
| 加密 Client API 请求 | `Crypto.postEncrypted(url, plain, pem)` |
|
package/dist/cjs/plugins.js
CHANGED
|
@@ -48,6 +48,25 @@ 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
|
+
/** 壳首次启动生成的设备序列号。与签名证书无关,覆盖安装后保持不变。 */
|
|
64
|
+
getInstallDeviceId(callback) {
|
|
65
|
+
return (0, runtime_1.withCallback)((0, runtime_1.invokeNative)('getInstallDeviceId'), callback);
|
|
66
|
+
},
|
|
67
|
+
requestPhoneStatePermission(callback) {
|
|
68
|
+
return (0, runtime_1.withCallback)((0, runtime_1.invokeNative)('requestPhoneStatePermission'), callback);
|
|
69
|
+
},
|
|
51
70
|
};
|
|
52
71
|
exports.Config = {
|
|
53
72
|
getNativeConfig(callback) {
|
package/dist/cjs/version.js
CHANGED
package/dist/native.d.ts
CHANGED
|
@@ -59,6 +59,12 @@ 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
|
+
getInstallDeviceId(callback?: import("./runtime").NativeCallback<import("./types").InstallDeviceId>): Promise<import("./types").InstallDeviceId>;
|
|
67
|
+
requestPhoneStatePermission(callback?: import("./runtime").NativeCallback<import("./types").PhoneStatePermissionResult>): Promise<import("./types").PhoneStatePermissionResult>;
|
|
62
68
|
};
|
|
63
69
|
readonly Config: {
|
|
64
70
|
getNativeConfig(callback?: import("./runtime").NativeCallback<import("./types").NativeFeatureConfig>): Promise<import("./types").NativeFeatureConfig>;
|
|
@@ -208,7 +214,7 @@ export declare const Native: {
|
|
|
208
214
|
readonly Push: {
|
|
209
215
|
getToken(callback?: import("./runtime").NativeCallback<import("./types").PushTokenResult>): Promise<import("./types").PushTokenResult>;
|
|
210
216
|
};
|
|
211
|
-
readonly sdkVersion: "1.
|
|
217
|
+
readonly sdkVersion: "1.5.0";
|
|
212
218
|
readonly getPlatform: typeof getPlatform;
|
|
213
219
|
readonly isNativePlatform: typeof isNativePlatform;
|
|
214
220
|
readonly isNativeBridgeAvailable: typeof isNativeBridgeAvailable;
|
|
@@ -265,6 +271,12 @@ export declare const Native: {
|
|
|
265
271
|
getOrientation(callback?: import("./runtime").NativeCallback<import("./types").OrientationInfo>): Promise<import("./types").OrientationInfo>;
|
|
266
272
|
getLockStatus(callback?: import("./runtime").NativeCallback<import("./types").LockStatus>): Promise<import("./types").LockStatus>;
|
|
267
273
|
getSystemInfo(callback?: import("./runtime").NativeCallback<import("./types").SystemInfo>): Promise<import("./types").SystemInfo>;
|
|
274
|
+
getAndroidId(callback?: import("./runtime").NativeCallback<Pick<import("./types").DeviceIdentifiers, "collectAllowed" | "androidId">>): Promise<Pick<import("./types").DeviceIdentifiers, "collectAllowed" | "androidId">>;
|
|
275
|
+
getImei(callback?: import("./runtime").NativeCallback<Pick<import("./types").DeviceIdentifiers, "collectAllowed" | "phoneStatePermissionGranted" | "imei">>): Promise<Pick<import("./types").DeviceIdentifiers, "collectAllowed" | "phoneStatePermissionGranted" | "imei">>;
|
|
276
|
+
getDeviceSerial(callback?: import("./runtime").NativeCallback<Pick<import("./types").DeviceIdentifiers, "collectAllowed" | "phoneStatePermissionGranted" | "serial">>): Promise<Pick<import("./types").DeviceIdentifiers, "collectAllowed" | "phoneStatePermissionGranted" | "serial">>;
|
|
277
|
+
getIdentifiers(callback?: import("./runtime").NativeCallback<import("./types").DeviceIdentifiers>): Promise<import("./types").DeviceIdentifiers>;
|
|
278
|
+
getInstallDeviceId(callback?: import("./runtime").NativeCallback<import("./types").InstallDeviceId>): Promise<import("./types").InstallDeviceId>;
|
|
279
|
+
requestPhoneStatePermission(callback?: import("./runtime").NativeCallback<import("./types").PhoneStatePermissionResult>): Promise<import("./types").PhoneStatePermissionResult>;
|
|
268
280
|
};
|
|
269
281
|
readonly Config: {
|
|
270
282
|
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, InstallDeviceId, 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,13 @@ 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
|
+
/** 壳首次启动生成的设备序列号。与签名证书无关,覆盖安装后保持不变。 */
|
|
29
|
+
getInstallDeviceId(callback?: NativeCallback<InstallDeviceId>): Promise<InstallDeviceId>;
|
|
30
|
+
requestPhoneStatePermission(callback?: NativeCallback<PhoneStatePermissionResult>): Promise<PhoneStatePermissionResult>;
|
|
24
31
|
};
|
|
25
32
|
export declare const Config: {
|
|
26
33
|
getNativeConfig(callback?: NativeCallback<NativeFeatureConfig>): Promise<NativeFeatureConfig>;
|
package/dist/plugins.js
CHANGED
|
@@ -45,6 +45,25 @@ 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
|
+
/** 壳首次启动生成的设备序列号。与签名证书无关,覆盖安装后保持不变。 */
|
|
61
|
+
getInstallDeviceId(callback) {
|
|
62
|
+
return withCallback(invokeNative('getInstallDeviceId'), callback);
|
|
63
|
+
},
|
|
64
|
+
requestPhoneStatePermission(callback) {
|
|
65
|
+
return withCallback(invokeNative('requestPhoneStatePermission'), callback);
|
|
66
|
+
},
|
|
48
67
|
};
|
|
49
68
|
export const Config = {
|
|
50
69
|
getNativeConfig(callback) {
|
package/dist/types.d.ts
CHANGED
|
@@ -269,6 +269,25 @@ export interface SetNativeFeaturesOptions {
|
|
|
269
269
|
/** 嵌套主题对象,便于与配置文件结构一致 */
|
|
270
270
|
theme?: SetAppThemeOptions;
|
|
271
271
|
}
|
|
272
|
+
/** Device.getInstallDeviceId():壳自行生成的设备序列号,与签名证书无关 */
|
|
273
|
+
export interface InstallDeviceId {
|
|
274
|
+
deviceId: string;
|
|
275
|
+
}
|
|
276
|
+
/** getDeviceIdentifiers / getAndroidId 等;须 store.collectDeviceIdsAfterConsent */
|
|
277
|
+
export interface DeviceIdentifiers {
|
|
278
|
+
collectAllowed: boolean;
|
|
279
|
+
phoneStatePermissionGranted?: boolean;
|
|
280
|
+
/** Android: ANDROID_ID;iOS: IDFV;Harmony: ODID */
|
|
281
|
+
androidId: string;
|
|
282
|
+
imei?: string;
|
|
283
|
+
serial?: string;
|
|
284
|
+
identifierForVendor?: string;
|
|
285
|
+
odid?: string;
|
|
286
|
+
}
|
|
287
|
+
export interface PhoneStatePermissionResult {
|
|
288
|
+
granted: boolean;
|
|
289
|
+
message?: string;
|
|
290
|
+
}
|
|
272
291
|
export interface DeviceInfo {
|
|
273
292
|
brand: string;
|
|
274
293
|
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 })` |
|
|
@@ -927,7 +928,59 @@ Device.getInfo().then(console.log);
|
|
|
927
928
|
}
|
|
928
929
|
```
|
|
929
930
|
|
|
930
|
-
> 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
|
+
#### `Device.getInstallDeviceId()`
|
|
960
|
+
|
|
961
|
+
壳在第一次启动时生成 32 位设备序列号并保存。值由安全随机数产生,与签名证书、`ANDROID_ID` / IDFV / ODID 无关,也不受 `collectDeviceIdsAfterConsent` 控制。同一安装上的覆盖更新保持不变。iOS 写在 Keychain 中,同一 Bundle ID、同一开发者 Team 卸载后重装仍是原值。Android 写在应用私有偏好中,覆盖安装不变;卸载后只有系统恢复了云备份时才会保留。Harmony 写在应用 preferences 中,覆盖安装不变,卸载重装会生成新值。
|
|
962
|
+
|
|
963
|
+
```javascript
|
|
964
|
+
Device.getInstallDeviceId().then(function (result) {
|
|
965
|
+
console.log(result.deviceId);
|
|
966
|
+
});
|
|
967
|
+
```
|
|
968
|
+
|
|
969
|
+
```json
|
|
970
|
+
{ "deviceId": "7f3a1c2e9b804d6fa1c2e9b804d6fa1c" }
|
|
971
|
+
```
|
|
972
|
+
|
|
973
|
+
单次返回示例(`getDeviceIdentifiers`):
|
|
974
|
+
|
|
975
|
+
```json
|
|
976
|
+
{
|
|
977
|
+
"collectAllowed": true,
|
|
978
|
+
"phoneStatePermissionGranted": true,
|
|
979
|
+
"androidId": "a1b2c3d4e5f67890",
|
|
980
|
+
"imei": "",
|
|
981
|
+
"serial": ""
|
|
982
|
+
}
|
|
983
|
+
```
|
|
931
984
|
|
|
932
985
|
#### `Device.getScreenInfo()`
|
|
933
986
|
|
|
@@ -1110,9 +1163,146 @@ Viewport.getWindowInfo().then(console.log);
|
|
|
1110
1163
|
|
|
1111
1164
|
### 7.3 桌面图标
|
|
1112
1165
|
|
|
1166
|
+
桌面图标有两条路,不要混用:
|
|
1167
|
+
|
|
1168
|
+
| 方式 | 图从哪来 | 谁来换 | 适用 |
|
|
1169
|
+
|------|----------|--------|------|
|
|
1170
|
+
| 预置槽 | 打包进安装包的 `default` / `alt1` / `alt2` | `Icon.set({ iconId })` | 三端里 Android、iOS 可在已烤入的槽位之间切换 |
|
|
1171
|
+
| 资源包图片 | 前端资源包里的 PNG | `Icon.setFromResource({ path })`,或 `app_config.json` 的 `desktopIcon` | **仅 Android 8+**。iOS、HarmonyOS 会返回失败 |
|
|
1172
|
+
|
|
1173
|
+
资源包图片会换成**当前这一个**桌面图标,不会再在桌面上多出一个同名应用。
|
|
1174
|
+
|
|
1175
|
+
#### 资源包里怎么放
|
|
1176
|
+
|
|
1177
|
+
把正方形 PNG 打进明文 `www.zip`,路径相对包根目录。服务端加密后,这张图在 `www.pkg` 里,`app_config.json` 仍是明文。
|
|
1178
|
+
|
|
1179
|
+
```text
|
|
1180
|
+
www.zip
|
|
1181
|
+
├── app_config.json
|
|
1182
|
+
├── index.html
|
|
1183
|
+
└── icons/
|
|
1184
|
+
├── app-icon.png # 默认桌面图标
|
|
1185
|
+
└── app-icon-festival.png # 可选:活动图标,由页面再切换
|
|
1186
|
+
```
|
|
1187
|
+
|
|
1188
|
+
`app_config.json`:
|
|
1189
|
+
|
|
1190
|
+
```json
|
|
1191
|
+
{
|
|
1192
|
+
"appName": "示例 App",
|
|
1193
|
+
"url": "/",
|
|
1194
|
+
"desktopIcon": "icons/app-icon.png"
|
|
1195
|
+
}
|
|
1196
|
+
```
|
|
1197
|
+
|
|
1198
|
+
| 规则 | 说明 |
|
|
1199
|
+
|------|------|
|
|
1200
|
+
| 路径 | `icons/app-icon.png`。不要写成 `/icons/...`、`www/icons/...`,也不要包含 `..` |
|
|
1201
|
+
| 图片 | 正方形 PNG。建议 512×512 或 1024×1024 |
|
|
1202
|
+
| 自动套用 | `desktopIcon` 非空时,Android 在**安装这份资源包之后**自动换上。同一份 `www.pkg` 只自动套用一次 |
|
|
1203
|
+
| 冷启动 | Android 11+ 若这份包还没套用过,冷启动会再套用一次。Android 8–10 冷启动**不会**再弹确认框,只在图标已经固定过时静默更新 |
|
|
1204
|
+
| 页面再切换 | 用户选了另一张图后调用 `Icon.setFromResource`。下一次冷启动不会用 `desktopIcon` 把这次选择盖掉 |
|
|
1205
|
+
|
|
1206
|
+
壳取图顺序:先解密热更新的 `www.pkg`,再解密安装包内置的 `www.pkg`,最后才看明文 `www/` 目录。
|
|
1207
|
+
|
|
1208
|
+
#### 先看当前系统能不能换
|
|
1209
|
+
|
|
1210
|
+
```typescript
|
|
1211
|
+
import { Icon, Native } from 'ota-native-bridge';
|
|
1212
|
+
|
|
1213
|
+
function applyDesktopIcon(path) {
|
|
1214
|
+
if (!Native.isNativePlatform()) {
|
|
1215
|
+
return;
|
|
1216
|
+
}
|
|
1217
|
+
Icon.get().then((current) => {
|
|
1218
|
+
if (!current.supportsCustomFromResource) {
|
|
1219
|
+
console.log('当前系统不能用资源包图片换桌面图标');
|
|
1220
|
+
return;
|
|
1221
|
+
}
|
|
1222
|
+
Icon.setFromResource({ path: path }).then((result) => {
|
|
1223
|
+
if (!result.success) {
|
|
1224
|
+
console.log(result.message);
|
|
1225
|
+
return;
|
|
1226
|
+
}
|
|
1227
|
+
if (result.pendingPinConfirmation) {
|
|
1228
|
+
console.log('请在系统对话框里允许添加图标');
|
|
1229
|
+
return;
|
|
1230
|
+
}
|
|
1231
|
+
console.log('桌面图标已更新', result.iconId);
|
|
1232
|
+
});
|
|
1233
|
+
});
|
|
1234
|
+
}
|
|
1235
|
+
|
|
1236
|
+
applyDesktopIcon('icons/app-icon.png');
|
|
1237
|
+
```
|
|
1238
|
+
|
|
1239
|
+
`supportsCustomFromResource`:Android 11+ 为 `true`;Android 8–10 只有当前桌面支持固定快捷方式时为 `true`;iOS、HarmonyOS 为 `false` 或不返回该字段。
|
|
1240
|
+
|
|
1241
|
+
#### 用资源包里的图换图标
|
|
1242
|
+
|
|
1243
|
+
```typescript
|
|
1244
|
+
Icon.setFromResource({ path: 'icons/app-icon.png' }).then(console.log);
|
|
1245
|
+
```
|
|
1246
|
+
|
|
1247
|
+
Android 11+ 返回示例:
|
|
1248
|
+
|
|
1249
|
+
```json
|
|
1250
|
+
{
|
|
1251
|
+
"success": true,
|
|
1252
|
+
"iconId": "custom",
|
|
1253
|
+
"message": "Home screen icon updated. Check the home screen.",
|
|
1254
|
+
"requiresLauncherRefresh": true,
|
|
1255
|
+
"pendingBackgroundFinalize": false,
|
|
1256
|
+
"pendingPinConfirmation": false
|
|
1257
|
+
}
|
|
1258
|
+
```
|
|
1259
|
+
|
|
1260
|
+
Android 8–10,系统确认框还在等用户点时:
|
|
1261
|
+
|
|
1262
|
+
```json
|
|
1263
|
+
{
|
|
1264
|
+
"success": true,
|
|
1265
|
+
"iconId": "custom",
|
|
1266
|
+
"message": "Confirm the new home screen icon.",
|
|
1267
|
+
"requiresLauncherRefresh": true,
|
|
1268
|
+
"pendingPinConfirmation": true
|
|
1269
|
+
}
|
|
1270
|
+
```
|
|
1271
|
+
|
|
1272
|
+
用户点允许后,让用户按一次 Home。原来的启动图标会被收起,桌面上只留新图标。同一张快捷方式之后再换图,直接更新,不再弹框。
|
|
1273
|
+
|
|
1274
|
+
| 字段 | 含义 |
|
|
1275
|
+
|------|------|
|
|
1276
|
+
| `success` | 是否已提交换图标。Android 8–10 弹出确认框时也是 `true` |
|
|
1277
|
+
| `iconId` | 成功时为 `custom` |
|
|
1278
|
+
| `pendingPinConfirmation` | `true`:Android 8–10 还在等系统确认,桌面图标尚未换成新图 |
|
|
1279
|
+
| `pendingBackgroundFinalize` | `true`:要等应用退到后台,旧的桌面入口才会关掉 |
|
|
1280
|
+
| `requiresLauncherRefresh` | `true`:回主屏才能看到新图标 |
|
|
1281
|
+
| `message` | 失败原因,或需要用户做的下一步 |
|
|
1282
|
+
|
|
1283
|
+
失败示例(路径不存在,或桌面不支持):
|
|
1284
|
+
|
|
1285
|
+
```json
|
|
1286
|
+
{ "success": false, "iconId": "default", "message": "Icon file not found: icons/app-icon.png" }
|
|
1287
|
+
```
|
|
1288
|
+
|
|
1289
|
+
#### 在几张资源包图片之间切换
|
|
1290
|
+
|
|
1291
|
+
```typescript
|
|
1292
|
+
function chooseIcon(id) {
|
|
1293
|
+
const file = id === 'festival' ? 'icons/app-icon-festival.png' : 'icons/app-icon.png';
|
|
1294
|
+
Icon.setFromResource({ path: file }).then((result) => {
|
|
1295
|
+
if (result.pendingPinConfirmation) {
|
|
1296
|
+
console.log('第一次需要在系统对话框里点允许');
|
|
1297
|
+
}
|
|
1298
|
+
});
|
|
1299
|
+
}
|
|
1300
|
+
```
|
|
1301
|
+
|
|
1302
|
+
#### 查询当前图标和预置槽
|
|
1303
|
+
|
|
1113
1304
|
```typescript
|
|
1114
1305
|
Icon.list().then(console.log);
|
|
1115
|
-
// 返回示例:
|
|
1116
1306
|
// {
|
|
1117
1307
|
// "icons": [
|
|
1118
1308
|
// { "id": "default", "label": "默认" },
|
|
@@ -1132,36 +1322,36 @@ Icon.list().then(console.log);
|
|
|
1132
1322
|
// }
|
|
1133
1323
|
|
|
1134
1324
|
Icon.get().then(console.log);
|
|
1135
|
-
// 返回示例:同 current
|
|
1325
|
+
// 返回示例:同 current
|
|
1136
1326
|
|
|
1137
1327
|
Icon.set({ iconId: 'alt1' }).then(console.log);
|
|
1138
|
-
//
|
|
1328
|
+
// { "success": true, "iconId": "alt1", "message": "ok", "requiresLauncherRefresh": false }
|
|
1329
|
+
```
|
|
1139
1330
|
|
|
1140
|
-
|
|
1141
|
-
// 返回示例:{ "success": true, "iconId": "custom", "message": "ok" }
|
|
1331
|
+
`launcherEntryCount` 应为 `1`。大于 `1` 表示桌面留过多余快捷方式,需要用户长按删掉。预置槽切换请用 Release 包;Debug 包调用 `Icon.set` 会失败。
|
|
1142
1332
|
|
|
1143
|
-
|
|
1144
|
-
// 返回示例:{ "success": true, "iconId": "custom", "message": "ok" }
|
|
1333
|
+
从默认图标第一次切到 `alt1` 时应用不会退出。返回 `pendingBackgroundFinalize: true` 时,按 Home 后旧入口才会关掉。
|
|
1145
1334
|
|
|
1146
|
-
|
|
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
|
-
```
|
|
1335
|
+
#### 远程图和 Base64
|
|
1152
1336
|
|
|
1153
|
-
`
|
|
1337
|
+
这两条和 `setFromResource` 一样,只在 Android 上把像素换成桌面图标。图不在资源包里时再用。
|
|
1154
1338
|
|
|
1155
|
-
|
|
1156
|
-
|
|
1157
|
-
|
|
1158
|
-
|
|
1159
|
-
|
|
1160
|
-
|
|
1339
|
+
```typescript
|
|
1340
|
+
Icon.setFromUrl({ url: 'https://cdn.example.com/icon.png' }).then(console.log);
|
|
1341
|
+
// { "success": true, "iconId": "custom", "message": "ok" }
|
|
1342
|
+
|
|
1343
|
+
Icon.setFromBase64({ base64: 'iVBORw0KGgo...' }).then(console.log);
|
|
1344
|
+
// { "success": true, "iconId": "custom", "message": "ok" }
|
|
1345
|
+
```
|
|
1161
1346
|
|
|
1162
|
-
|
|
1347
|
+
#### 各系统实际效果
|
|
1163
1348
|
|
|
1164
|
-
|
|
1349
|
+
| 系统 | `setFromResource` | `Icon.set` 预置槽 |
|
|
1350
|
+
|------|-------------------|-------------------|
|
|
1351
|
+
| Android 11+ | 直接盖住当前桌面入口,没有确认框 | 切换已烤入的 `activity-alias` |
|
|
1352
|
+
| Android 8–10 | 系统确认一次后固定快捷方式;按 Home 收起原图标 | 同上 |
|
|
1353
|
+
| iOS | `success: false` | `default` / `alt1` / `alt2`,系统可能再弹一次确认 |
|
|
1354
|
+
| HarmonyOS | `success: false` | 运行时不能改,需重新出安装包 |
|
|
1165
1355
|
|
|
1166
1356
|
### 7.4 通知与角标
|
|
1167
1357
|
|
|
@@ -1499,6 +1689,9 @@ A:管理后台「公共接口」可单独关闭端点;与 Bridge 无关,
|
|
|
1499
1689
|
**Q:TypeScript 提示找不到类型?**
|
|
1500
1690
|
A:执行 `npm run build` 生成 `dist/*.d.ts`,或确认依赖版本已包含类型文件。
|
|
1501
1691
|
|
|
1692
|
+
**Q:`Icon.setFromResource` 调用了但桌面图标没变?**
|
|
1693
|
+
A:先看 `Icon.get()` 的 `supportsCustomFromResource`。iOS 和 HarmonyOS 会返回失败。Android 8–10 若 `pendingPinConfirmation` 为 `true`,需要用户在系统对话框里点允许,再按一次 Home。路径必须是资源包内相对路径,例如 `icons/app-icon.png`,图要打进 `www.zip` 后由服务端加密进 `www.pkg`。
|
|
1694
|
+
|
|
1502
1695
|
---
|
|
1503
1696
|
|
|
1504
1697
|
## 11. 相关文档
|
package/ota-native-bridge.js
CHANGED
|
@@ -122,7 +122,13 @@
|
|
|
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
|
+
getInstallDeviceId: function (cb) { return withCallback(invokeNative('getInstallDeviceId'), cb); },
|
|
131
|
+
requestPhoneStatePermission: function (cb) { return withCallback(invokeNative('requestPhoneStatePermission'), cb); }
|
|
126
132
|
};
|
|
127
133
|
|
|
128
134
|
var Config = {
|
|
@@ -366,7 +372,7 @@
|
|
|
366
372
|
};
|
|
367
373
|
|
|
368
374
|
global.Native = {
|
|
369
|
-
sdkVersion: '1.
|
|
375
|
+
sdkVersion: '1.5.0',
|
|
370
376
|
getPlatform: getPlatform,
|
|
371
377
|
isNativePlatform: isNativePlatform,
|
|
372
378
|
isNativeBridgeAvailable: function () { return !!getNativeMessenger(); },
|