You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

使用ConsentDebugSettings.Builder添加测试设备哈希ID无效问题排查

解决ConsentDebugSettings设置后日志提示仍存在的问题

你犯的问题很明确:只创建了ConsentDebugSettings实例,但没有将它关联到 consent 请求的参数中,也没有完成完整的 consent 配置初始化,所以系统依然识别不到你的调试设备。

正确的操作步骤是:

  • 构建ConsentDebugSettings后,需要将其传入ConsentRequestParameters.Builder
  • 用构建好的ConsentRequestParameters初始化ConsentInformation
  • 确保整个 consent 流程的代码正确关联这些配置

结合你原有的广告初始化代码,完整的正确实现如下:

// 保留你原来的MobileAds初始化代码
MobileAds.initialize(this)
val testDeviceIds = listOf(
    "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX",
    // 其他测试设备ID
)
val configuration = RequestConfiguration
    .Builder()
    .setTestDeviceIds(testDeviceIds)
    .build()
MobileAds.setRequestConfiguration(configuration)

// 正确配置ConsentDebugSettings并关联到consent请求
val consentDebugSettings = ConsentDebugSettings.Builder(this)
    .addTestDeviceHashedId("XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX")
    .build()

val consentRequestParameters = ConsentRequestParameters.Builder()
    .setConsentDebugSettings(consentDebugSettings)
    // 按需添加其他参数,比如setTagForUnderAgeOfConsent(true)
    .build()

// 初始化ConsentInformation并发起更新请求
ConsentInformation.getInstance(this).requestConsentInfoUpdate(
    consentRequestParameters,
    object : ConsentInfoUpdateListener {
        override fun onConsentInfoUpdated(consentStatus: ConsentStatus) {
            // 处理 consent 状态更新逻辑
        }

        override fun onFailedToUpdateConsentInfo(errorDescription: String) {
            // 处理错误逻辑
        }
    }
)

核心问题在于:你之前只调用build()创建了ConsentDebugSettings对象,但没有把它传递给ConsentRequestParameters,也没有触发consent信息的更新请求,系统自然无法识别这是调试设备,日志提示就会反复出现。

内容的提问来源于stack exchange,提问作者Mark Delphi

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.04 09:42:35