通过以下代码段检查并将广告ID视为null值。
AdvertisingIdClient.Info adInfo = null;
try {
adInfo = AdvertisingIdClient.getAdvertisingIdInfo(context);
} catch (IOException | GooglePlayServicesNotAvailableException | GooglePlayServicesRepairableException e) {
e.printStackTrace();
}
if (adInfo != null && !adInfo.isLimitAdTrackingEnabled()) {
String advertisingId = adInfo.getId();
// 在此处处理广告ID
} else {
String advertisingId = null;
// 在此处处理广告ID为null的情况
}