AppGallery Kit为使用动态图标的应用客户端提供查询动态图标信息、切换动态图标、恢复默认图标功能。
从版本5.0.3(15)开始,支持实现应用图标动态切换。
图标管理服务不支持模拟器,请使用真机调试。
图标管理服务支持Phone、Tablet、PC/2in1设备。从5.1.0(18)版本开始,新增支持Wearable设备;从5.1.1(19)版本开始,新增支持TV设备;并且从API版本26.0.1开始,新增支持Car设备。
图标管理服务提供以下接口,具体API说明详见接口文档。
| 接口名 | 描述 |
|---|---|
| queryDynamicIcons(): Promise<DynamicIconInfo[]> | 查询动态图标信息接口,用于查询动态图标信息。 |
| selectDynamicIcon(iconId: string): Promise<void> | 切换动态图标接口,用于切换动态图标。 |
| disableDynamicIcon(): Promise<void> | 禁用动态图标接口,用于停止动态图标,恢复默认图标。 |
从版本6.0.0(20)开始,切换动态图标接口支持返回1006800013错误码。
导入appInfoManager模块及相关公共模块。
import { hilog } from '@kit.PerformanceAnalysisKit';
import { appInfoManager } from '@kit.AppGalleryKit';
import { BusinessError } from '@kit.BasicServicesKit'; 调用queryDynamicIcons方法查询动态图标信息。
try {
appInfoManager.queryDynamicIcons().then((iconInfos: appInfoManager.DynamicIconInfo[]) => {
hilog.info(0, TAG, `queryDynamicIcons success. iconInfos: ${JSON.stringify(iconInfos)}`);
// ...
}).catch((error: BusinessError) => {
hilog.error(0, TAG,
`queryDynamicIcons failed, code: ${error.code}, exception message: ${error.message}`);
// ...
})
} catch (error) {
hilog.error(0, TAG,
`queryDynamicIcons exception, code: ${error.code}, exception message: ${error.message}`);
// ...
} 导入appInfoManager模块及相关公共模块。
import { hilog } from '@kit.PerformanceAnalysisKit';
import { appInfoManager } from '@kit.AppGalleryKit';
import { BusinessError } from '@kit.BasicServicesKit'; 调用selectDynamicIcon方法切换动态图标。
public selectDynamicIcon(iconId: string) {
try {
appInfoManager.selectDynamicIcon(iconId).then(() => {
hilog.info(0, TAG, `selectDynamicIcon success. iconId: ${iconId}`);
// ...
}).catch((error: BusinessError) => {
hilog.error(0, TAG,
`selectDynamicIcon failed, code: ${error.code}, exception message: ${error.message}`);
// ...
});
} catch (error) {
hilog.error(0, TAG,
`selectDynamicIcon exception, code: ${error.code}, exception message: ${error.message}`);
// ...
}
} 导入appInfoManager模块及相关公共模块。
import { hilog } from '@kit.PerformanceAnalysisKit';
import { appInfoManager } from '@kit.AppGalleryKit';
import { BusinessError } from '@kit.BasicServicesKit'; 调用disableDynamicIcon方法恢复默认图标。
try {
appInfoManager.disableDynamicIcon().then(() => {
hilog.info(0, TAG, `disableDynamicIcon success.`);
// ...
}).catch((error: BusinessError) => {
hilog.error(0, TAG,
`disableDynamicIcon failed, code: ${error.code}, exception message: ${error.message}`);
// ...
});
} catch (error) {
hilog.error(0, TAG,
`disableDynamicIcon exception, code: ${error.code}, exception message: ${error.message}`);
// ...
}