| 12345678910111213141516171819202122232425262728293031 |
- import { native, sys } from 'cc';
- import { PlatformBridge } from './PlatformBridge';
- import { PlatformType } from './PlatformBridge';
- const LOCAL_DEVICE_CODE = "AndroidDeviceCode";
- export class AndroidPlatformBridge extends PlatformBridge {
- readonly type = PlatformType.Android;
- getUrlParam(_name: string): string | null {
- console.error('[Android] 获取深度链接参数能力未实现');
- return null;
- }
- getDeviceID(): string | null {
- let deviceCode = sys.localStorage.getItem(LOCAL_DEVICE_CODE);
- if (!!deviceCode && deviceCode.length > 0) return deviceCode;
- deviceCode = native.reflection.callStaticMethod("com/cocos/helper/Utils", "getDeviceCode", "()Ljava/lang/String;");
- if (!deviceCode || deviceCode.length === 0) {
- console.warn(`[Android] 获取设备号为空,自动创建设备号...`);
- deviceCode = "";
- const characters = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789';
- for (let i = 0; i < 50; i++) {
- deviceCode += characters.charAt(Math.floor(Math.random() * characters.length));
- }
- }
- sys.localStorage.setItem(LOCAL_DEVICE_CODE, deviceCode);
- return deviceCode;
- }
- }
|