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

API 33 Android应用添加AD_ID权限后仍获取全0广告ID问题

问题分析与解决方案

首先你犯了一个核心错误:你在Manifest里配置的是移除com.google.android.gms.permission.AD_ID权限,而不是声明该权限。tools:node="remove"的作用是将这个权限从最终打包的Manifest中剔除,这直接导致你的应用没有获取广告ID所需的权限,自然会返回全0的ID值。

正确的Manifest配置

要在targetSDK 33下正常获取Google Advertising ID,你需要主动声明该权限,而非移除:

<uses-permission android:name="com.google.android.gms.permission.AD_ID" />

如果你的项目依赖库自动引入了这个权限,之前的tools:node="remove"完全是反向操作,必须删除这行配置,或者改为tools:node="merge"确保权限被保留在最终Manifest中。

额外排查点

  • Google Play服务版本:确保测试设备上的Google Play服务为最新版本,旧版本可能对Android 13的权限逻辑支持存在问题。
  • 代码调用逻辑:你自定义的AdvertisingInterface中,isLimitAdTrackingEnabled(true)的调用可能存在封装错误——官方AdvertisingIdClient.Info的isLimitAdTrackingEnabled()是无参方法。建议直接使用官方API简化获取逻辑,避免自定义绑定服务的潜在问题:
    import com.google.android.gms.ads.identifier.AdvertisingIdClient
    import com.google.android.gms.common.GooglePlayServicesNotAvailableException
    import com.google.android.gms.common.GooglePlayServicesRepairableException
    import java.io.IOException
    
    fun getAdvertisingIdInfo(context: Context): Pair<String, Boolean> {
        check(Looper.myLooper() != Looper.getMainLooper()) { "Cannot be called from the main thread" }
        return try {
            val info = AdvertisingIdClient.getAdvertisingIdInfo(context)
            Pair(info.id, info.isLimitAdTrackingEnabled)
        } catch (e: IOException) {
            throw e
        } catch (e: GooglePlayServicesNotAvailableException) {
            throw e
        } catch (e: GooglePlayServicesRepairableException) {
            throw e
        }
    }
    
  • 设备设置确认:核实测试设备的广告个性化设置未被禁用,一般路径为:设置 > 隐私 > 广告 > 关闭「限制广告跟踪」(不同品牌设备路径可能略有差异)。

内容的提问来源于stack exchange,提问作者nayan dhabarde

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.08.08 20:35:30