HarmonyOS 鸿蒙Next 获取OAID报错,错误码305
HarmonyOS 鸿蒙Next 获取OAID报错,错误码305 咨询描述:
日志:
[oaid_service_proxy.cpp] GetOAID failed, error code is: 305
请确认下305是什么错误?如何处理?
2 回复
305是没权限,需要动态授权
代码上要动态获取
import abilityAccessCtrl from '@ohos.abilityAccessCtrl';
import { BusinessError } from '@ohos.base';
import hilog from '@ohos.hilog';
private requestOAIDTrackingConsentPermissions(context: common.Context): void {
// 进入页面时触发动态授权弹框,向用户请求授权广告跟踪权限
const atManager: abilityAccessCtrl.AtManager = abilityAccessCtrl.createAtManager();
try {
atManager.requestPermissionsFromUser(context, ["ohos.permission.APP_TRACKING_CONSENT"]).then((data) => {
if (data.authResults[0] == 0) {
hilog.info(0x0000, 'testTag', '%{public}s', 'request permission success');
} else {
hilog.info(0x0000, 'testTag', '%{public}s', user rejected);
}
}).catch((err) => {
const e: BusinessError = err as BusinessError;
hilog.error(0x0000, 'testTag', '%{public}s', request permission failed, error message: ${e.message});
})
} catch(err) {
const e: BusinessError = err as BusinessError;
hilog.error(0x0000, 'testTag', '%{public}s', catch err->${JSON.stringify(e)});
}
}
更多关于HarmonyOS 鸿蒙Next 获取OAID报错,错误码305的实战系列教程也可以访问 https://www.itying.com/category-93-b0.html