中国优质的IT技术网站
专业IT技术创作平台
IT职业在线教育平台
FA模型下如何获取KvManager实例?
微信扫码分享
// 导入模块 import distributedKVStore from '@ohos.data.distributedKVStore'; import { BusinessError } from '@ohos.base'; // FA模型 import featureAbility from '@ohos.ability.featureAbility'; let kvManager: distributedKVStore.KVManager | undefined = undefined; let context = featureAbility.getContext(); // 获取context const kvManagerConfig: distributedKVStore.KVManagerConfig = { context: context, bundleName: 'com.example.datamanagertest' }; try { kvManager = distributedKVStore.createKVManager(kvManagerConfig); console.info('Succeeded in creating KVManager.'); // 继续创建获取数据库 } catch (e) { let error = e as BusinessError; console.error(`Failed to create KVManager. Code:${error.code},message:${error.message}`); } if (kvManager !== undefined) { kvManager = kvManager as distributedKVStore.KVManager; //进行后续操作 //... }