HarmonyOS鸿蒙Next中Theme studio Pro真机调试怎么查看主题APP的ODID
HarmonyOS鸿蒙Next中Theme studio Pro真机调试怎么查看主题APP的ODID Theme studo Pro真机调试怎么查看主题APP的ODID
背景知识:
1、Theme Studio Pro 预览 / 真机调试:只是把你的主题资源(hwt)推送到设备上的系统主题引擎预览,不跑你的 App 代码,所以这里看不到 ODID。
2、在你的主题 App 页面(比如 index.ets)加入获取 ODID 代码:
@Entry
@Component
struct TestPage {
aboutToAppear() {
// 直接取 ODID(无需权限)
let odid: string = deviceInfo.ODID;
console.log('### ODID ###', odid);
}
build() {
Column() {
Text('ODID:' + deviceInfo.ODID) // 页面直接显示
.fontSize(14)
}
.width('100%')
.height('100%')
.justifyContent(FlexAlign.Center)
}
}
更多关于HarmonyOS鸿蒙Next中Theme studio Pro真机调试怎么查看主题APP的ODID的实战系列教程也可以访问 https://www.itying.com/category-93-b0.html
import { deviceInfo } from ‘@kit.BasicServicesKit’; let odid: string = deviceInfo.ODID;
-
如果这个《主题App》,是你开发的(比如用DevEco IDE),可以通过代码获取下:
Text('ODID:'+deviceInfo.ODID) -
如果是系统自带的华为《主题》App,那是获取不到的。
ODID是开发者匿名设备标识符。
ODID值会在以下场景重新生成:
手机恢复出厂设置。
同一设备上同一个开发者(developerId相同)的应用全部卸载后重新安装时。
ODID生成规则:
根据签名信息里developerId解析出的groupId生成,developerId规则为groupId.developerId,若无groupId则取整个developerId作为groupId。
同一设备上运行的同一个开发者(developerId相同)的应用,ODID相同。
同一个设备上不同开发者(developerId不同)的应用,ODID不同。
不同设备上同一个开发者(developerId相同)的应用,ODID不同。
不同设备上不同开发者(developerId不同)的应用,ODID不同。
说明:数据长度为37字节(包含结束符)。
示例:1234a567-XXXX-XXXX-XXXX-XXXXXXXXXXXX
参考这个:
https://gitcode.com/HarmonyOS_Samples/ObtainingDeviceID
/*
* Copyright (c) 2024 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import { CreateIDComponent } from '../view/CreateIDComponent';
@Entry
@Component
struct Index {
@Provide('pageInfos') pageInfos: NavPathStack = new NavPathStack();
@Builder
PageMap(name: string, param: string) {
CreateIDComponent({ typeId: param })
}
build() {
Navigation(this.pageInfos) {
Column() {
Column({ space: 12 }) {
Button($r('app.string.ODID'))
.width('100%')
.borderRadius(20)
.backgroundColor('#0A59F7')
.onClick(() => {
this.pageInfos.pushPathByName('default', 'ODID');
})
Button($r('app.string.AAID'))
.width('100%')
.borderRadius(20)
.backgroundColor('#0A59F7')
.onClick(() => {
this.pageInfos.pushPathByName('default', 'AAID');
})
Button($r('app.string.OAID'))
.width('100%')
.borderRadius(20)
.backgroundColor('#0A59F7')
.margin({ bottom: 16 })
.onClick(() => {
this.pageInfos.pushPathByName('default', 'OAID');
})
}
.width('100%')
.justifyContent(FlexAlign.End)
}
.width('100%')
.height('100%')
.padding({
left: 16,
right: 16
})
.justifyContent(FlexAlign.End)
}
.title($r('app.string.Title'))
.height('100%')
.width('100%')
.backgroundColor('#F1F3F5')
.navDestination(this.PageMap)
}
}
简单,你在调试运行的时候,在日志里面查看就可以了啊,比如在你主题 APP 入口页面添加获取 ODID 代码。ODID 为开发者维度标识,同签名包共用,无系统 shell 查询指令,只能应用内代码读取。
取值规则:同一设备、同一个 DeveloperId(签名)的全部应用 ODID 完全一致;不同签名 ODID 不同
获取方式:import { deviceInfo } from ‘@kit.BasicServicesKit’; let odid:string=deviceInfo.ODID;,无需申请任何权限,直接取值。
类似下面代码这样
import { deviceInfo } from '[@kit](/user/kit).BasicServicesKit'
import hilog from '@ohos.hilog'
aboutToAppear(){
let odid = deviceInfo.ODID
hilog.info(0x0001,"THEME_ODID","ODID=%s",odid)
}
不清楚
要在使用Theme Studio Pro进行真机调试时查看主题APP的ODID,目前没有查询到直接相关的官方操作步骤。
不过,根据通用的鸿蒙应用开发知识,如果您想在自己的应用(包括主题APP)中获取ODID,可以参考以下方法:
-
添加权限
在应用的配置文件中,需要添加 APP_TRACKING_CONSENT 权限,这是获取ODID的前提条件。 -
编写代码获取
通过调用 @ohos.deviceInfo 模块中的API来获取设备信息,其中就包含了ODID1。
一个简化的代码示例如下:
import deviceInfo from '[@ohos](/user/ohos).deviceInfo';
async function getODID() {
try {
let deviceInfoObj = await deviceInfo.getDeviceInfo();
let odid = deviceInfoObj.odid;
console.log('ODID:', odid);
return odid;
} catch (error) {
console.error('获取ODID失败:', error);
}
}
请注意 :
以上代码需要集成到您的主题APP的源码中,并通过编译和运行后才能在日志中查看到ODID。
由于Theme Studio Pro主要用于主题的可视化制作和预览,它可能并未内置直接查看ODID的功能。建议您通过在主题APP的代码中加入上述逻辑,然后在真机调试的日志输出中查看ODID值。
在Theme Studio Pro中连接真机后,点击“设备管理”或“调试”选项卡,选中目标设备,在设备详情页可查看ODID。若未显示,可运行hdc shell cat /data/app/el1/100/base/<主题APP包名>/odid获取,包名需自行替换。
ODID是应用的设备唯一标识,可在真机调试时通过子线程获取:
- 运行主题App后,在Theme Studio Pro的Log/控制台中筛选
ODID关键字,查看打出的日志。 - 或者在代码中调用系统API
bundleManager.getBundleInfoForSelf获取signatureInfo,其中包含odin字段,打印到日志即可在DevEco Studio的Log窗口查看。

